Export (0) Print
Expand All

ZipArchive.CreateFromDirectory Method (String, String, CompressionLevel, Boolean)

Creates a Zip archive at the path destinationArchive that contains the files and directories in the directory specified by sourceDirectoryName. The directory structure is preserved in the archive, and a recursive search is performed for files to be archived. The archive must not exist. If the directory is empty, an empty archive will be created.

If a file in the directory cannot be added to the archive, the archive will be left incomplete and invalid and the method will throw an exception. This method optionally includes the base directory in the archive.

If an error is encountered when adding files to the archive, this method will stop adding files and leave the archive in an invalid state. The paths are permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. If a file in the archive has data in the last write time field that is not a valid Zip timestamp, an indicator value of 1980 January 1 at midnight will be used for the file's last modified time.

Namespace:  Microsoft.TeamFoundation.Framework.Server
Assembly:  Microsoft.TeamFoundation.Framework.Server (in Microsoft.TeamFoundation.Framework.Server.dll)

public static void CreateFromDirectory(
	string sourceDirectoryName,
	string destinationArchiveFileName,
	CompressionLevel compressionLevel,
	bool includeBaseDirectory
)

Parameters

sourceDirectoryName
Type: System.String

The path of the directory on the file system to be archived.

destinationArchiveFileName
Type: System.String

The name of the archive to be created.

compressionLevel
Type: Microsoft.TeamFoundation.Framework.Server.CompressionLevel

The level of the compression (speed/memory vs. compressed size trade-off).

includeBaseDirectory
Type: System.Boolean

True to indicate that a directory named sourceDirectoryName should be included at the root of the archive. False to indicate that the files and directories in sourceDirectoryName should be included directly in the archive.

ExceptionCondition
ArgumentException

sourceDirectoryName or destinationArchive is a zero-length string, or it contains only white space, or it contains one or more invalid characters as defined by InvalidPathChars.

ArgumentNullException

sourceDirectoryName or destinationArchive is null.

PathTooLongException

In sourceDirectoryName or destinationArchive, the specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

DirectoryNotFoundException

The path specified in sourceDirectoryName or destinationArchive is invalid, (for example, it is on an unmapped drive), or the directory specified by sourceDirectoryName does not exist.

IOException

destinationArchive exists, or an I/O error occurred while you are opening a file to be archived.

UnauthorizedAccessException

destinationArchive specified a directory, or the caller does not have the required permission.

NotSupportedException

sourceDirectoryName or destinationArchive is in an invalid format.

Show:
© 2014 Microsoft