Delen via


ZipArchive.ExtractToDirectory Method (String, String)

Extracts all of the files in the specified archive to a directory on the file system. The specified directory must not exist. This method will create all subdirectories and the specified directory. If there is an error while extracting the archive, the archive will remain partially extracted. Each entry will be extracted such that the extracted file has the same relative path to the destinationDirectoryName as the entry has to the archive. The path is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. If a file to be archived has an invalid last modified time, the first datetime representable in the Zip timestamp format (midnight on January 1, 1980) will be used.

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

Syntax

'Declaration
Public Shared Sub ExtractToDirectory ( _
    sourceArchiveFileName As String, _
    destinationDirectoryName As String _
)
public static void ExtractToDirectory(
    string sourceArchiveFileName,
    string destinationDirectoryName
)
public:
static void ExtractToDirectory(
    String^ sourceArchiveFileName, 
    String^ destinationDirectoryName
)
static member ExtractToDirectory : 
        sourceArchiveFileName:string * 
        destinationDirectoryName:string -> unit
public static function ExtractToDirectory(
    sourceArchiveFileName : String, 
    destinationDirectoryName : String
)

Parameters

  • sourceArchiveFileName
    Type: System.String

    The path to the archive on the file system that is to be extracted.

  • destinationDirectoryName
    Type: System.String

    The path to the directory on the file system. The directory specified must not exist, but the directory that it is contained in must exist.

Exceptions

Exception Condition
ArgumentException

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

ArgumentNullException

sourceArchive or destinationDirectoryName is null.

PathTooLongException

sourceArchive or destinationDirectoryName specifies a 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 by sourceArchive or destinationDirectoryName is invalid, (for example, it is on an unmapped drive).

IOException

The directory specified by destinationDirectoryName already exists. -or- An I/O error has occurred. -or- An archive entry’s name is zero-length, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars. -or- Extracting an archive entry would result in a file destination that is outside the destination directory (for example, because of parent directory accessors). -or- An archive entry has the same name as an already extracted entry from the same archive.

UnauthorizedAccessException

The caller does not have the required permission.

NotSupportedException

sourceArchive or destinationDirectoryName is in an invalid format.

FileNotFoundException

sourceArchive was not found.

InvalidDataException

The archive specified by sourceArchive: Is not a valid ZipArchive -or- An archive entry was not found or was corrupt. -or- An archive entry has been compressed using a compression method that is not supported.

.NET Framework Security

See Also

Reference

ZipArchive Class

ExtractToDirectory Overload

Microsoft.TeamFoundation.Server.Core Namespace