C# | Visual Basic | Visual C++ |
- directoryName (String)
- The name of the directory to add.
- directoryPathInArchive (String)
- Specifies a directory path to use to override any path in the DirectoryName. This path may, or may not, correspond to a real directory in the current filesystem. If the zip is later extracted, this is the path used for the extracted file or directory. Passing null (Nothing in VB) or the empty string ("") will insert the items at the root path within the archive.
The name of the directory may be a relative path or a fully-qualified path. The add operation is recursive, so that any files or subdirectories within the name directory are also added to the archive.
Top-level entries in the named directory will appear as top-level entries in the zip archive. Entries in subdirectories in the named directory will result in entries in subdirectories in the zip archive.
For ZipFile properties including Encryption, Password, SetCompression, ProvisionalAlternateEncoding, ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to each ZipEntry added.
In this code, calling the ZipUp() method with a value of "c:\reports" for the directory parameter will result in a zip file structure in which all entries are contained in a toplevel "reports" directory.
public void ZipUp(string targetZip, string directory) { using (var zip = new ZipFile()) { zip.AddDirectory(directory, System.IO.Path.GetFileName(directory)); zip.Save(targetZip); } }