AddDirectory Method (directoryName, directoryPathInArchive)

DotNetZip

Ionic Zip Library v1.9.1.6 AddDirectory Method (directoryName, directoryPathInArchive)
ReferenceIonic.ZipZipFileAddDirectory(String, String)
Adds the contents of a filesystem directory to a Zip file archive, overriding the path to be used for entries in the archive.
Declaration Syntax
C# Visual Basic Visual C++
public ZipEntry AddDirectory(
	string directoryName,
	string directoryPathInArchive
)
Public Function AddDirectory ( _
	directoryName As String, _
	directoryPathInArchive As String _
) As ZipEntry
public:
ZipEntry^ AddDirectory(
	String^ directoryName, 
	String^ directoryPathInArchive
)
Parameters
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.
Return Value
The ZipEntry added.
Remarks

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.

Examples

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.

CopyC#
public void ZipUp(string targetZip, string directory)
{
  using (var zip = new ZipFile())
  {
    zip.AddDirectory(directory, System.IO.Path.GetFileName(directory));
    zip.Save(targetZip);
  }
}

Assembly: Ionic.Zip (Module: Ionic.Zip) Version: 1.9.1.8 (1.9.1.8)