ZipFileExtensions.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.
Extracts all of the files in the archive to a directory on the file system. The specified directory may already exist.
Overloads
| Name | Description |
|---|---|
| ExtractToDirectoryAsync(ZipArchive, String, CancellationToken) |
Asynchronously extracts all of the files in the archive to a directory on the file system. The specified directory can already exist. |
| ExtractToDirectoryAsync(ZipArchive, String, Boolean, CancellationToken) |
Extracts all of the files in the archive to a directory on the file system. The specified directory can already exist. |
| ExtractToDirectoryAsync(ZipArchive, String, ZipExtractionOptions, CancellationToken) |
ExtractToDirectoryAsync(ZipArchive, String, CancellationToken)
Asynchronously extracts all of the files in the archive to a directory on the file system. The specified directory can already exist.
public static System.Threading.Tasks.Task ExtractToDirectoryAsync(this System.IO.Compression.ZipArchive source, string destinationDirectoryName, System.Threading.CancellationToken cancellationToken = default);
static member ExtractToDirectoryAsync : System.IO.Compression.ZipArchive * string * System.Threading.CancellationToken -> System.Threading.Tasks.Task
<Extension()>
Public Function ExtractToDirectoryAsync (source As ZipArchive, destinationDirectoryName As String, Optional cancellationToken As CancellationToken = Nothing) As Task
Parameters
- source
- ZipArchive
The zip archive to extract files from.
- 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.
- cancellationToken
- CancellationToken
The cancellation token to monitor for cancellation requests.
Returns
Exceptions
destinationDirectoryName is a zero-length string, contains only whitespace, or contains one or more invalid characters as defined by InvalidPathChars.
destinationDirectoryName is null.
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.
The specified path is invalid, (for example, it is on an unmapped drive).
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 have resulted in a destination file that is outside destinationDirectoryName (for example, if the entry name contains 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.
destinationDirectoryName is in an invalid format.
An archive entry was not found or is corrupt.
-or-
An archive entry has been compressed using a compression method that is not 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.
The path is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working 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 destinationDirectoryName as the entry has to the root of the archive. 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.
Applies to
ExtractToDirectoryAsync(ZipArchive, String, Boolean, CancellationToken)
Extracts all of the files in the archive to a directory on the file system. The specified directory can already exist.
public static System.Threading.Tasks.Task ExtractToDirectoryAsync(this System.IO.Compression.ZipArchive source, string destinationDirectoryName, bool overwriteFiles, System.Threading.CancellationToken cancellationToken = default);
static member ExtractToDirectoryAsync : System.IO.Compression.ZipArchive * string * bool * System.Threading.CancellationToken -> System.Threading.Tasks.Task
<Extension()>
Public Function ExtractToDirectoryAsync (source As ZipArchive, destinationDirectoryName As String, overwriteFiles As Boolean, Optional cancellationToken As CancellationToken = Nothing) As Task
Parameters
- source
- ZipArchive
The zip archive to extract files from.
- 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.
- overwriteFiles
- Boolean
true to overwrite files; false otherwise.
- cancellationToken
- CancellationToken
The cancellation token to monitor for cancellation requests.
Returns
Exceptions
destinationDirectoryName is a zero-length string, contains only whitespace, or contains one or more invalid characters as defined by InvalidPathChars.
This method creates missing directories as needed when extracting entries.
If there is an error while extracting the archive, the archive will remain partially extracted.
Each entry is extracted such that the extracted file has the same relative path to destinationDirectoryName as the entry has to the root of the archive. 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.
destinationDirectoryName is null.
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.
The specified path is invalid, (for example, it is on an unmapped drive).
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 have resulted in a destination file that is outside destinationDirectoryName (for example, if the entry name contains 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.
destinationDirectoryName is in an invalid format.
An archive entry was not found or was corrupt.
-or-
An archive entry has been compressed using a compression method that is not supported.
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.
The path is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory.
Applies to
ExtractToDirectoryAsync(ZipArchive, String, ZipExtractionOptions, CancellationToken)
public static System.Threading.Tasks.Task ExtractToDirectoryAsync(this System.IO.Compression.ZipArchive source, string destinationDirectoryName, System.IO.Compression.ZipExtractionOptions options, System.Threading.CancellationToken cancellationToken = default);
static member ExtractToDirectoryAsync : System.IO.Compression.ZipArchive * string * System.IO.Compression.ZipExtractionOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task
<Extension()>
Public Function ExtractToDirectoryAsync (source As ZipArchive, destinationDirectoryName As String, options As ZipExtractionOptions, Optional cancellationToken As CancellationToken = Nothing) As Task
Parameters
- source
- ZipArchive
- 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.
EntryNameEncoding isn't used by this overload. Entry names and comments are decoded using the encoding specified when the source archive is opened.
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.