/// <summary> /// Adds a set of files to the <c>ZipFile</c>, using the /// specified directory path in the archive. /// </summary> /// /// <remarks> /// <para> /// Any directory structure that may be present in the /// filenames contained in the list is "flattened" in the /// archive. Each file in the list is added to the archive in /// the specified top-level directory. /// </para> /// /// <para> /// For <c>ZipFile</c> properties including <see /// cref="Encryption"/>, <see cref="Password"/>, <see /// cref="SetCompression"/>, <see /// cref="ProvisionalAlternateEncoding"/>, <see /// cref="ExtractExistingFile"/>, <see /// cref="ZipErrorAction"/>, and <see /// cref="CompressionLevel"/>, their respective values at the /// time of this call will be applied to each ZipEntry added. /// </para> /// </remarks> /// /// <param name="fileNames"> /// The names of the files to add. Each string should refer to /// a file in the filesystem. The name of the file may be a /// relative path or a fully-qualified path. /// </param> /// /// <param name="directoryPathInArchive"> /// Specifies a directory path to use to override any path in the file name. /// Th is path may, or may not, correspond to a real directory in the current /// filesystem. If the files within the zip are later extracted, this is the /// path used for the extracted file. Passing <c>null</c> (<c>Nothing</c> in /// VB) will use the path on each of the <c>fileNames</c>, if any. Passing /// the empty string ("") will insert the item at the root path within the /// archive. /// </param> /// /// <seealso cref="Ionic.Zip.ZipFile.AddSelectedFiles(String, String)" /> public static void AddFiles(this ZipFile zipFile, System.Collections.Generic.IEnumerable<String> fileNames, String directoryPathInArchive) { zipFile.AddFiles(fileNames, directoryPathInArchive, false); }
/// <summary> /// This method adds a set of files to the <c>ZipFile</c>. /// </summary> /// /// <remarks> /// <para> /// Use this method to add a set of files to the zip archive, in one call. /// For example, a list of files received from /// <c>System.IO.Directory.GetFiles()</c> can be added to a zip archive in one /// call. /// </para> /// /// <para> /// For <c>ZipFile</c> properties including <see cref="Encryption"/>, <see /// cref="Password"/>, <see cref="SetCompression"/>, <see /// cref="ProvisionalAlternateEncoding"/>, <see cref="ExtractExistingFile"/>, /// <see cref="ZipErrorAction"/>, and <see cref="CompressionLevel"/>, their /// respective values at the time of this call will be applied to each /// ZipEntry added. /// </para> /// </remarks> /// /// <param name="fileNames"> /// The collection of names of the files to add. Each string should refer to a /// file in the filesystem. The name of the file may be a relative path or a /// fully-qualified path. /// </param> /// /// <example> /// This example shows how to create a zip file, and add a few files into it. /// <code> /// String ZipFileToCreate = "archive1.zip"; /// String DirectoryToZip = "c:\\reports"; /// using (ZipFile zip = new ZipFile()) /// { /// // Store all files found in the top level directory, into the zip archive. /// String[] filenames = System.IO.Directory.GetFiles(DirectoryToZip); /// zip.AddFiles(filenames); /// zip.Save(ZipFileToCreate); /// } /// </code> /// /// <code lang="VB"> /// Dim ZipFileToCreate As String = "archive1.zip" /// Dim DirectoryToZip As String = "c:\reports" /// Using zip As ZipFile = New ZipFile /// ' Store all files found in the top level directory, into the zip archive. /// Dim filenames As String() = System.IO.Directory.GetFiles(DirectoryToZip) /// zip.AddFiles(filenames) /// zip.Save(ZipFileToCreate) /// End Using /// </code> /// </example> /// /// <seealso cref="Ionic.Zip.ZipFile.AddSelectedFiles(String, String)" /> public static void AddFiles(this ZipFile zipFile, System.Collections.Generic.IEnumerable<String> fileNames) { zipFile.AddFiles(fileNames, null); }