ZipFile.ExtractToDirectoryAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Asynchronously extracts all of the files in the specified archive to a directory on the file system.
Overloads
| Name | Description |
|---|---|
| ExtractToDirectoryAsync(String, String, Encoding, Boolean, CancellationToken) |
Asynchronously extracts all of the files in the specified archive to a directory on the file system. The specified directory can already exist. Missing directories are created as needed when extracting entries. 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. |
| ExtractToDirectoryAsync(Stream, String, Encoding, Boolean, CancellationToken) |
Asynchronously extracts all the files from the zip archive stored in the specified stream and places them in the specified destination directory on the file system, uses the specified character encoding for entry names, and optionally allows choosing if the files in the destination directory should be overwritten. |
| ExtractToDirectoryAsync(String, String, Encoding, CancellationToken) |
Asynchronously extracts all of the files in the specified archive to a directory on the file system. |
| ExtractToDirectoryAsync(String, String, ZipExtractionOptions, CancellationToken) | |
| ExtractToDirectoryAsync(String, String, Boolean, CancellationToken) |
Asynchronously extracts all of the files in the specified archive to a directory on the file system. |
| ExtractToDirectoryAsync(Stream, String, ZipExtractionOptions, CancellationToken) | |
| ExtractToDirectoryAsync(Stream, String, Boolean, CancellationToken) |
Asynchronously extracts all the files from the zip archive stored in the specified stream and places them in the specified destination directory on the file system, and optionally allows choosing if the files in the destination directory should be overwritten. |
| ExtractToDirectoryAsync(String, String, CancellationToken) |
Asynchronously extracts all of the files in the specified archive to a directory on the file system. |
| ExtractToDirectoryAsync(Stream, String, CancellationToken) |
Asynchronously extracts all the files from the zip archive stored in the specified stream and places them in the specified destination directory on the file system. |
| ExtractToDirectoryAsync(Stream, String, Encoding, CancellationToken) |
Asynchronously extracts all the files from the zip archive stored in the specified stream and places them in the specified destination directory on the file system and uses the specified character encoding for entry names. |
ExtractToDirectoryAsync(String, String, Encoding, Boolean, CancellationToken)
- Source:
- ZipFile.Extract.Async.cs
- Source:
- ZipFile.Extract.Async.cs
Asynchronously extracts all of the files in the specified archive to a directory on the file system.
The specified directory can already exist. Missing directories are created as needed when extracting entries.
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.
public static System.Threading.Tasks.Task ExtractToDirectoryAsync(string sourceArchiveFileName, string destinationDirectoryName, System.Text.Encoding? entryNameEncoding, bool overwriteFiles, System.Threading.CancellationToken cancellationToken = default);
static member ExtractToDirectoryAsync : string * string * System.Text.Encoding * bool * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Shared Function ExtractToDirectoryAsync (sourceArchiveFileName As String, destinationDirectoryName As String, entryNameEncoding As Encoding, overwriteFiles As Boolean, Optional cancellationToken As CancellationToken = Nothing) As Task
Parameters
- sourceArchiveFileName
- String
The path to the archive on the file system that is to be extracted.
- destinationDirectoryName
- String
The path to the directory in which to place the extracted files, specified as a relative or absolute path. A relative path is interpreted as relative to the current working directory. The directory can already exist. Missing directories are created as needed when extracting entries.
- entryNameEncoding
- Encoding
The encoding to use when reading or writing entry names and comments in this ZipArchive.
- overwriteFiles
- Boolean
true to overwrite files; false otherwise.
- cancellationToken
- CancellationToken
The cancellation token to monitor for cancellation requests.
Returns
Exceptions
sourceArchiveFileName or destinationDirectoryName is a zero-length string, contains only whitespace, or contains one or more invalid characters as defined by InvalidPathChars.
sourceArchiveFileName or destinationDirectoryName is null.
sourceArchiveFileName or destinationDirectoryName specifies a path, file name, or both that exceeds 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.
The path specified by sourceArchiveFileName or destinationDirectoryName is invalid, (for example, it is on an unmapped drive).
An I/O error has occurred.
-or-
An archive entry's name is zero-length, contains only whitespace, 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.
The caller does not have the required permission.
sourceArchiveFileName or destinationDirectoryName is in an invalid format.
sourceArchiveFileName was not found.
The archive specified by sourceArchiveFileName 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 isn't supported.
An asynchronous operation is cancelled.
Remarks
Warning
This method must not be used to extract untrusted archives. It doesn't enforce any size limits, entry count limits, or other policies needed for safe extraction of untrusted archives. For more information on safely extracting archives from untrusted sources, see Best practices for using zip and tar archives.
The directory specified by destinationDirectoryName can already exist. This method creates the destination directory, its missing parent directories, and subdirectories as needed when extracting entries. If the archive is empty, this method doesn't create the destination directory.
If entryNameEncoding is set to a value other than null, entry names and comments are decoded according to the following rules:
- For entries where the language encoding flag (EFS) in the general purpose bit flag of the local file header is not set, use the specified
entryNameEncodingto decode the entry name and comment. - For entries where the language encoding flag (EFS) in the general purpose bit flag of the local file header is set, use UTF-8 (
Encoding.UTF8) to decode the entry name and comment.
If entryNameEncoding is set to null, entry names and comments are decoded according to the following rules:
- For entries where the language encoding flag (EFS) in the general purpose bit flag of the local file header is not set, use the current system default code page (
Encoding.Default) to decode the entry name and comment. - For entries where the language encoding flag (EFS) in the general purpose bit flag of the local file header is set, use UTF-8 (
Encoding.UTF8) to decode the entry name and comment.
Unicode encodings other than UTF-8 can't be used for entryNameEncoding, otherwise an ArgumentException is thrown.
Applies to
ExtractToDirectoryAsync(Stream, String, Encoding, Boolean, CancellationToken)
- Source:
- ZipFile.Create.cs
- Source:
- ZipFile.Extract.Async.cs
Asynchronously extracts all the files from the zip archive stored in the specified stream and places them in the specified destination directory on the file system, uses the specified character encoding for entry names, and optionally allows choosing if the files in the destination directory should be overwritten.
public static System.Threading.Tasks.Task ExtractToDirectoryAsync(System.IO.Stream source, string destinationDirectoryName, System.Text.Encoding? entryNameEncoding, bool overwriteFiles, System.Threading.CancellationToken cancellationToken = default);
static member ExtractToDirectoryAsync : System.IO.Stream * string * System.Text.Encoding * bool * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Shared Function ExtractToDirectoryAsync (source As Stream, destinationDirectoryName As String, entryNameEncoding As Encoding, overwriteFiles As Boolean, Optional cancellationToken As CancellationToken = Nothing) As Task
Parameters
- source
- Stream
The stream from which the zip archive is to be extracted.
- destinationDirectoryName
- String
The path to the directory in which to place the extracted files, specified as a relative or absolute path. A relative path is interpreted as relative to the current working directory. The directory can already exist. Missing directories are created as needed when extracting entries.
- entryNameEncoding
- Encoding
The encoding to use when reading or writing entry names and comments in this archive. Specify a value for this parameter only when an encoding is required for interoperability with zip archive tools and libraries that do not support UTF-8 encoding for entry names or comments.
- overwriteFiles
- Boolean
true to overwrite files; false otherwise.
- cancellationToken
- CancellationToken
The cancellation token to monitor for cancellation requests.
Returns
Exceptions
destinationDirectoryName is Empty, contains only white space, or contains at least one invalid character.
-or-
entryNameEncoding is set to a Unicode encoding other than UTF-8.
destinationDirectoryName or source is null.
The specified path in destinationDirectoryName exceeds the system-defined maximum length.
The specified path is invalid (for example, it is on an unmapped drive).
The name of an entry in the archive is Empty, contains only white space, or contains at least one invalid character.
-or-
Extracting an archive entry would create a file that is outside the directory specified by destinationDirectoryName. (For example, this might happen if the entry name contains parent directory accessors.)
-or-
overwriteFiles is false and an archive entry to extract has the same name as an entry that has already been extracted or that exists in destinationDirectoryName.
The caller does not have the required permission to access the archive or the destination directory.
destinationDirectoryName contains an invalid format.
The archive contained in the source stream is not a valid zip archive.
-or-
An archive entry was not found or was corrupt.
-or-
An archive entry was compressed by using a compression method that isn't supported.
An asynchronous operation is cancelled.
Remarks
Warning
This method must not be used to extract untrusted archives. It doesn't enforce any size limits, entry count limits, or other policies needed for safe extraction of untrusted archives. For more information on safely extracting archives from untrusted sources, see Best practices for using zip and tar archives.
The directory specified by destinationDirectoryName can already exist. This method creates the destination directory, its missing parent directories, and subdirectories as needed when extracting entries. If the archive is empty, this method doesn't create the destination directory.
Exceptions related to validating the paths in the destinationDirectoryName or the files in the zip archive contained in the source parameters are thrown before extraction. Otherwise, if an error occurs during extraction, the archive remains partially extracted. Each extracted file has the same relative path to the directory specified by destinationDirectoryName as its source entry has to the root of the archive.
If a file to be archived has an invalid last modified time, the first date and time representable in the zip timestamp format (midnight on January 1, 1980) will be used.
Applies to
ExtractToDirectoryAsync(String, String, Encoding, CancellationToken)
- Source:
- ZipFile.Extract.Async.cs
- Source:
- ZipFile.Extract.Async.cs
Asynchronously extracts all of the files in the specified archive to a directory on the file system.
public static System.Threading.Tasks.Task ExtractToDirectoryAsync(string sourceArchiveFileName, string destinationDirectoryName, System.Text.Encoding? entryNameEncoding, System.Threading.CancellationToken cancellationToken = default);
static member ExtractToDirectoryAsync : string * string * System.Text.Encoding * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Shared Function ExtractToDirectoryAsync (sourceArchiveFileName As String, destinationDirectoryName As String, entryNameEncoding As Encoding, Optional cancellationToken As CancellationToken = Nothing) As Task
Parameters
- sourceArchiveFileName
- String
The path to the archive on the file system that is to be extracted.
- destinationDirectoryName
- String
The path to the directory on the file system. The directory can already exist. Missing directories are created as needed when extracting entries.
- entryNameEncoding
- Encoding
The encoding to use when reading or writing entry names and comments in this ZipArchive.
- cancellationToken
- CancellationToken
The cancellation token to monitor for cancellation requests.
Returns
Exceptions
sourceArchiveFileName or destinationDirectoryName is a zero-length string, contains only whitespace, or contains one or more invalid characters as defined by InvalidPathChars.
sourceArchiveFileName or destinationDirectoryName is null.
sourceArchiveFileName or destinationDirectoryName specifies a path, file name, or both that exceeds 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.
The path specified by sourceArchiveFileName or destinationDirectoryName is invalid, (for example, it is on an unmapped drive).
An I/O error has occurred.
-or-
An archive entry's name is zero-length, contains only whitespace, 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.
The caller does not have the required permission.
sourceArchiveFileName or destinationDirectoryName is in an invalid format.
sourceArchiveFileName was not found.
The archive specified by sourceArchiveFileName 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 isn't supported.
An asynchronous operation is cancelled.
Remarks
Warning
This method must not be used to extract untrusted archives. It doesn't enforce any size limits, entry count limits, or other policies needed for safe extraction of untrusted archives. For more information on safely extracting archives from untrusted sources, see Best practices for using zip and tar archives.
The directory specified by destinationDirectoryName can already exist. This method creates the destination directory, its missing parent directories, and subdirectories as needed when extracting entries. If the archive is empty, this method doesn't create the destination directory.
If there is an error while extracting the archive, the archive remains partially extracted. Each entry is extracted such that the extracted file has the same relative path to the destinationDirectoryName as the entry has to the archive. The path accepts relative or absolute path information; relative paths are interpreted as relative to the current working directory.
If a file to be archived has an invalid last modified time, the first date and time representable in the zip timestamp format (midnight on January 1, 1980) will be used.
If entryNameEncoding is set to a value other than null, entry names and comments are decoded according to the following rules:
- For entries where the language encoding flag (EFS) in the general purpose bit flag of the local file header is not set, use the specified
entryNameEncodingto decode the entry name and comment. - For entries where the language encoding flag (EFS) in the general purpose bit flag of the local file header is set, use UTF-8 (
Encoding.UTF8) to decode the entry name and comment.
If entryNameEncoding is set to null, entry names and comments are decoded according to the following rules:
- For entries where the language encoding flag (EFS) in the general purpose bit flag of the local file header is not set, use the current system default code page (
Encoding.Default) to decode the entry name and comment. - For entries where the language encoding flag (EFS) in the general purpose bit flag of the local file header is set, use UTF-8 (
Encoding.UTF8) to decode the entry name and comment.
Unicode encodings other than UTF-8 can't be used for entryNameEncoding, otherwise an ArgumentException is thrown.
Applies to
ExtractToDirectoryAsync(String, String, ZipExtractionOptions, CancellationToken)
- Source:
- ZipFile.Extract.Async.cs
public static System.Threading.Tasks.Task ExtractToDirectoryAsync(string sourceArchiveFileName, string destinationDirectoryName, System.IO.Compression.ZipExtractionOptions options, System.Threading.CancellationToken cancellationToken = default);
static member ExtractToDirectoryAsync : string * string * System.IO.Compression.ZipExtractionOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Shared Function ExtractToDirectoryAsync (sourceArchiveFileName As String, destinationDirectoryName As String, options As ZipExtractionOptions, Optional cancellationToken As CancellationToken = Nothing) As Task
Parameters
- sourceArchiveFileName
- String
- destinationDirectoryName
- String
The path to the directory in which to place the extracted files. The directory can already exist. Missing directories are created as needed when extracting entries.
- options
- ZipExtractionOptions
- cancellationToken
- CancellationToken
Returns
Remarks
Warning
This method must not be used to extract untrusted archives. It doesn't enforce any size limits, entry count limits, or other policies needed for safe extraction of untrusted archives. For more information on safely extracting archives from untrusted sources, see Best practices for using zip and tar archives.
The directory specified by destinationDirectoryName can already exist. This method creates the destination directory, its missing parent directories, and subdirectories as needed when extracting entries. If the archive is empty, this method doesn't create the destination directory.
Each extracted file has the same relative path to destinationDirectoryName as its source entry has to the root of the archive.
The sourceArchiveFileName and destinationDirectoryName parameters accept relative and absolute paths. A relative path is interpreted as relative to the current working directory.
If an error occurs during extraction, the archive remains partially extracted.
Set OverwriteFiles to true to overwrite existing files. The default is false, which causes extraction to throw an IOException if a file to be extracted already exists.
Use Password to supply the password for encrypted entries.
Use EntryNameEncoding to specify the encoding for entry names and comments when opening the archive. For details about how this encoding is used, see ZipArchive(Stream, ZipArchiveMode, Boolean, Encoding).
Symbolic links in the archive aren't recreated as symbolic links. If destinationDirectoryName or any of its parent directories is a pre-existing junction or symbolic link, the link is followed and extraction writes to the final target folder.
Exceptions that occur during asynchronous extraction are stored in the returned task and are thrown when the task is awaited.
Applies to
ExtractToDirectoryAsync(String, String, Boolean, CancellationToken)
- Source:
- ZipFile.Extract.Async.cs
- Source:
- ZipFile.Extract.Async.cs
Asynchronously extracts all of the files in the specified archive to a directory on the file system.
public static System.Threading.Tasks.Task ExtractToDirectoryAsync(string sourceArchiveFileName, string destinationDirectoryName, bool overwriteFiles, System.Threading.CancellationToken cancellationToken = default);
static member ExtractToDirectoryAsync : string * string * bool * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Shared Function ExtractToDirectoryAsync (sourceArchiveFileName As String, destinationDirectoryName As String, overwriteFiles As Boolean, Optional cancellationToken As CancellationToken = Nothing) As Task
Parameters
- sourceArchiveFileName
- String
The path to the archive on the file system that is to be extracted.
- destinationDirectoryName
- String
The path to the directory in which to place the extracted files, specified as a relative or absolute path. A relative path is interpreted as relative to the current working directory. The directory can already exist. Missing directories are created as needed when extracting entries.
- overwriteFiles
- Boolean
true to overwrite files; false otherwise.
- cancellationToken
- CancellationToken
The cancellation token to monitor for cancellation requests.
Returns
Exceptions
sourceArchiveFileName or destinationDirectoryName is a zero-length string, contains only whitespace, or contains one or more invalid characters as defined by InvalidPathChars.
sourceArchiveFileName or destinationDirectoryName is null.
sourceArchiveFileName or destinationDirectoryName specifies a path, file name, or both that exceeds 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.
The path specified by sourceArchiveFileName or destinationDirectoryName is invalid, (for example, it is on an unmapped drive).
An I/O error has occurred.
-or-
An archive entry's name is zero-length, contains only whitespace, 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.
The caller does not have the required permission.
sourceArchiveFileName or destinationDirectoryName is in an invalid format.
sourceArchiveFileName was not found.
sourceArchiveFileName 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 isn't supported.
An asynchronous operation is cancelled.
Remarks
Warning
This method must not be used to extract untrusted archives. It doesn't enforce any size limits, entry count limits, or other policies needed for safe extraction of untrusted archives. For more information on safely extracting archives from untrusted sources, see Best practices for using zip and tar archives.
The directory specified by destinationDirectoryName can already exist. This method creates the destination directory, its missing parent directories, and subdirectories as needed when extracting entries. If the archive is empty, this method doesn't create the destination directory.
If there is an error while extracting the archive, the archive remains partially extracted. Each entry is extracted such that the extracted file has the same relative path to the destinationDirectoryName as the entry has to the archive. The path accepts relative or absolute path information; relative paths are interpreted as relative to the current working directory.
If a file to be archived has an invalid last modified time, the first date and time representable in the zip timestamp format (midnight on January 1, 1980) will be used.
Applies to
ExtractToDirectoryAsync(Stream, String, ZipExtractionOptions, CancellationToken)
- Source:
- ZipFile.Extract.Async.cs
public static System.Threading.Tasks.Task ExtractToDirectoryAsync(System.IO.Stream source, string destinationDirectoryName, System.IO.Compression.ZipExtractionOptions options, System.Threading.CancellationToken cancellationToken = default);
static member ExtractToDirectoryAsync : System.IO.Stream * string * System.IO.Compression.ZipExtractionOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Shared Function ExtractToDirectoryAsync (source As Stream, destinationDirectoryName As String, options As ZipExtractionOptions, Optional cancellationToken As CancellationToken = Nothing) As Task
Parameters
- source
- Stream
- destinationDirectoryName
- String
The path to the directory in which to place the extracted files. The directory can already exist. Missing directories are created as needed when extracting entries.
- options
- ZipExtractionOptions
- cancellationToken
- CancellationToken
Returns
Remarks
Warning
This method must not be used to extract untrusted archives. It doesn't enforce any size limits, entry count limits, or other policies needed for safe extraction of untrusted archives. For more information on safely extracting archives from untrusted sources, see Best practices for using zip and tar archives.
The directory specified by destinationDirectoryName can already exist. This method creates the destination directory, its missing parent directories, and subdirectories as needed when extracting entries. If the archive is empty, this method doesn't create the destination directory.
Each extracted file has the same relative path to destinationDirectoryName as its source entry has to the root of the archive.
The destinationDirectoryName parameter accepts relative and absolute paths. A relative path is interpreted as relative to the current working directory.
If an error occurs during extraction, the archive remains partially extracted.
Set OverwriteFiles to true to overwrite existing files. The default is false, which causes extraction to throw an IOException if a file to be extracted already exists.
Use Password to supply the password for encrypted entries.
Use EntryNameEncoding to specify the encoding for entry names and comments when opening the archive. For details about how this encoding is used, see ZipArchive(Stream, ZipArchiveMode, Boolean, Encoding).
Symbolic links in the archive aren't recreated as symbolic links. If destinationDirectoryName or any of its parent directories is a pre-existing junction or symbolic link, the link is followed and extraction writes to the final target folder.
The source stream is left open after extraction.
Exceptions that occur during asynchronous extraction are stored in the returned task and are thrown when the task is awaited.
Applies to
ExtractToDirectoryAsync(Stream, String, Boolean, CancellationToken)
- Source:
- ZipFile.Extract.Async.cs
- Source:
- ZipFile.Extract.Async.cs
Asynchronously extracts all the files from the zip archive stored in the specified stream and places them in the specified destination directory on the file system, and optionally allows choosing if the files in the destination directory should be overwritten.
public static System.Threading.Tasks.Task ExtractToDirectoryAsync(System.IO.Stream source, string destinationDirectoryName, bool overwriteFiles, System.Threading.CancellationToken cancellationToken = default);
static member ExtractToDirectoryAsync : System.IO.Stream * string * bool * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Shared Function ExtractToDirectoryAsync (source As Stream, destinationDirectoryName As String, overwriteFiles As Boolean, Optional cancellationToken As CancellationToken = Nothing) As Task
Parameters
- source
- Stream
The stream from which the zip archive is to be extracted.
- destinationDirectoryName
- String
The path to the directory in which to place the extracted files, specified as a relative or absolute path. A relative path is interpreted as relative to the current working directory. The directory can already exist. Missing directories are created as needed when extracting entries.
- overwriteFiles
- Boolean
true to overwrite files; false otherwise.
- cancellationToken
- CancellationToken
The cancellation token to monitor for cancellation requests.
Returns
Exceptions
destinationDirectoryName is Empty, contains only white space, or contains at least one invalid character.
destinationDirectoryName or source is null.
The specified path in destinationDirectoryName exceeds the system-defined maximum length.
The specified path is invalid (for example, it is on an unmapped drive).
The name of an entry in the archive is Empty, contains only white space, or contains at least one invalid character.
-or-
Extracting an archive entry would create a file that is outside the directory specified by destinationDirectoryName. (For example, this might happen if the entry name contains parent directory accessors.)
-or-
overwriteFiles is false and an archive entry to extract has the same name as an entry that has already been extracted or that exists in destinationDirectoryName.
The caller does not have the required permission to access the archive or the destination directory.
destinationDirectoryName contains an invalid format.
The archive contained in the source stream is not a valid zip archive.
-or-
An archive entry was not found or was corrupt.
-or-
An archive entry was compressed by using a compression method that isn't supported.
An asynchronous operation is cancelled.
Remarks
Warning
This method must not be used to extract untrusted archives. It doesn't enforce any size limits, entry count limits, or other policies needed for safe extraction of untrusted archives. For more information on safely extracting archives from untrusted sources, see Best practices for using zip and tar archives.
The directory specified by destinationDirectoryName can already exist. This method creates the destination directory, its missing parent directories, and subdirectories as needed when extracting entries. If the archive is empty, this method doesn't create the destination directory.
Exceptions related to validating the paths in the destinationDirectoryName or the files in the zip archive contained in the source parameters are thrown before extraction. Otherwise, if an error occurs during extraction, the archive remains partially extracted. Each extracted file has the same relative path to the directory specified by destinationDirectoryName as its source entry has to the root of the archive.
If a file to be archived has an invalid last modified time, the first date and time representable in the zip timestamp format (midnight on January 1, 1980) will be used.
Applies to
ExtractToDirectoryAsync(String, String, CancellationToken)
- Source:
- ZipFile.Extract.Async.cs
- Source:
- ZipFile.Extract.Async.cs
Asynchronously extracts all of the files in the specified archive to a directory on the file system.
public static System.Threading.Tasks.Task ExtractToDirectoryAsync(string sourceArchiveFileName, string destinationDirectoryName, System.Threading.CancellationToken cancellationToken = default);
static member ExtractToDirectoryAsync : string * string * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Shared Function ExtractToDirectoryAsync (sourceArchiveFileName As String, destinationDirectoryName As String, Optional cancellationToken As CancellationToken = Nothing) As Task
Parameters
- sourceArchiveFileName
- String
The path to the archive on the file system that is to be extracted.
- destinationDirectoryName
- String
The path to the directory in which to place the extracted files, specified as a relative or absolute path. A relative path is interpreted as relative to the current working directory. The directory can already exist. Missing directories are created as needed when extracting entries.
- cancellationToken
- CancellationToken
The cancellation token to monitor for cancellation requests.
Returns
Exceptions
sourceArchiveFileName or destinationDirectoryName is a zero-length string, contains only whitespace, or contains one or more invalid characters as defined by InvalidPathChars.
sourceArchiveFileName or destinationDirectoryName is null.
sourceArchiveFileName or destinationDirectoryName specifies a path, file name, or both that exceeds 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.
The path specified by sourceArchiveFileName or destinationDirectoryName is invalid, (for example, it is on an unmapped drive).
An I/O error has occurred.
-or-
An archive entry's name is zero-length, contains only whitespace, 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.
The caller does not have the required permission.
sourceArchiveFileName or destinationDirectoryName is in an invalid format.
sourceArchiveFileName was not found.
The archive specified by sourceArchiveFileName 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 isn't supported.
An asynchronous operation is cancelled.
Remarks
Warning
This method must not be used to extract untrusted archives. It doesn't enforce any size limits, entry count limits, or other policies needed for safe extraction of untrusted archives. For more information on safely extracting archives from untrusted sources, see Best practices for using zip and tar archives.
The directory specified by destinationDirectoryName can already exist. This method creates the destination directory, its missing parent directories, and subdirectories as needed when extracting entries. If the archive is empty, this method doesn't create the destination directory.
If there is an error while extracting the archive, the archive remains partially extracted. Each entry is extracted such that the extracted file has the same relative path to the destinationDirectoryName as the entry has to the archive. The path accepts relative or absolute path information; relative paths are interpreted as relative to the current working directory.
If a file to be archived has an invalid last modified time, the first date and time representable in the zip timestamp format (midnight on January 1, 1980) will be used.
Applies to
ExtractToDirectoryAsync(Stream, String, CancellationToken)
- Source:
- ZipFile.Extract.Async.cs
- Source:
- ZipFile.Extract.Async.cs
Asynchronously extracts all the files from the zip archive stored in the specified stream and places them in the specified destination directory on the file system.
public static System.Threading.Tasks.Task ExtractToDirectoryAsync(System.IO.Stream source, string destinationDirectoryName, System.Threading.CancellationToken cancellationToken = default);
static member ExtractToDirectoryAsync : System.IO.Stream * string * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Shared Function ExtractToDirectoryAsync (source As Stream, destinationDirectoryName As String, Optional cancellationToken As CancellationToken = Nothing) As Task
Parameters
- source
- Stream
The stream from which the zip archive is to be extracted.
- destinationDirectoryName
- String
The path to the directory in which to place the extracted files, specified as a relative or absolute path. A relative path is interpreted as relative to the current working directory. The directory can already exist. Missing directories are created as needed when extracting entries.
- cancellationToken
- CancellationToken
The cancellation token to monitor for cancellation requests.
Returns
Exceptions
destinationDirectoryName is Empty, contains only white space, or contains at least one invalid character.
destinationDirectoryName or source is null.
The specified path in destinationDirectoryName exceeds the system-defined maximum length.
The specified path is invalid (for example, it is on an unmapped drive).
The name of an entry in the archive is Empty, contains only white space, or contains at least one invalid character.
-or-
Extracting an archive entry would create a file that is outside the directory specified by destinationDirectoryName. (For example, this might happen if the entry name contains parent directory accessors.)
-or-
An archive entry to extract has the same name as an entry that has already been extracted or that exists in destinationDirectoryName.
The caller does not have the required permission to access the archive or the destination directory.
destinationDirectoryName contains an invalid format.
The archive contained in the source stream is not a valid zip archive.
-or-
An archive entry was not found or was corrupt.
-or-
An archive entry was compressed by using a compression method that isn't supported.
An asynchronous operation is cancelled.
Remarks
Warning
This method must not be used to extract untrusted archives. It doesn't enforce any size limits, entry count limits, or other policies needed for safe extraction of untrusted archives. For more information on safely extracting archives from untrusted sources, see Best practices for using zip and tar archives.
The directory specified by destinationDirectoryName can already exist. This method creates the destination directory, its missing parent directories, and subdirectories as needed when extracting entries. If the archive is empty, this method doesn't create the destination directory.
Exceptions related to validating the paths in the destinationDirectoryName or the files in the zip archive contained in the source parameters are thrown before extraction. Otherwise, if an error occurs during extraction, the archive remains partially extracted. Each extracted file has the same relative path to the directory specified by destinationDirectoryName as its source entry has to the root of the archive.
If a file to be archived has an invalid last modified time, the first date and time representable in the zip timestamp format (midnight on January 1, 1980) will be used.
Applies to
ExtractToDirectoryAsync(Stream, String, Encoding, CancellationToken)
- Source:
- ZipFile.Extract.Async.cs
- Source:
- ZipFile.Extract.Async.cs
Asynchronously extracts all the files from the zip archive stored in the specified stream and places them in the specified destination directory on the file system and uses the specified character encoding for entry names.
public static System.Threading.Tasks.Task ExtractToDirectoryAsync(System.IO.Stream source, string destinationDirectoryName, System.Text.Encoding? entryNameEncoding, System.Threading.CancellationToken cancellationToken = default);
static member ExtractToDirectoryAsync : System.IO.Stream * string * System.Text.Encoding * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Shared Function ExtractToDirectoryAsync (source As Stream, destinationDirectoryName As String, entryNameEncoding As Encoding, Optional cancellationToken As CancellationToken = Nothing) As Task
Parameters
- source
- Stream
The stream from which the zip archive is to be extracted.
- destinationDirectoryName
- String
The path to the directory in which to place the extracted files, specified as a relative or absolute path. A relative path is interpreted as relative to the current working directory. The directory can already exist. Missing directories are created as needed when extracting entries.
- entryNameEncoding
- Encoding
The encoding to use when reading or writing entry names and comments in this archive. Specify a value for this parameter only when an encoding is required for interoperability with zip archive tools and libraries that do not support UTF-8 encoding for entry names or comments.
- cancellationToken
- CancellationToken
The cancellation token to monitor for cancellation requests.
Returns
Exceptions
destinationDirectoryName is Empty, contains only white space, or contains at least one invalid character.
-or-
entryNameEncoding is set to a Unicode encoding other than UTF-8.
destinationDirectoryName or source is null.
The specified path in destinationDirectoryName exceeds the system-defined maximum length.
The specified path is invalid (for example, it is on an unmapped drive).
The name of an entry in the archive is Empty, contains only white space, or contains at least one invalid character.
-or-
Extracting an archive entry would create a file that is outside the directory specified by destinationDirectoryName. (For example, this might happen if the entry name contains parent directory accessors.)
-or-
An archive entry to extract has the same name as an entry that has already been extracted or that exists in destinationDirectoryName.
The caller does not have the required permission to access the archive or the destination directory.
destinationDirectoryName contains an invalid format.
The archive contained in the source stream is not a valid zip archive.
-or-
An archive entry was not found or was corrupt.
-or-
An archive entry was compressed by using a compression method that isn't supported.
An asynchronous operation is cancelled.
Remarks
Warning
This method must not be used to extract untrusted archives. It doesn't enforce any size limits, entry count limits, or other policies needed for safe extraction of untrusted archives. For more information on safely extracting archives from untrusted sources, see Best practices for using zip and tar archives.
The directory specified by destinationDirectoryName can already exist. This method creates the destination directory, its missing parent directories, and subdirectories as needed when extracting entries. If the archive is empty, this method doesn't create the destination directory.
Exceptions related to validating the paths in the destinationDirectoryName or the files in the zip archive contained in the source parameters are thrown before extraction. Otherwise, if an error occurs during extraction, the archive remains partially extracted. Each extracted file has the same relative path to the directory specified by destinationDirectoryName as its source entry has to the root of the archive.
If a file to be archived has an invalid last modified time, the first date and time representable in the zip timestamp format (midnight on January 1, 1980) will be used.