ZipFileExtensions.ExtractToDirectory Method (ZipArchive, String)
Extracts all the files in the zip archive to a directory on the file system.
Assembly: System.IO.Compression.FileSystem (in System.IO.Compression.FileSystem.dll)
<ExtensionAttribute> Public Shared Sub ExtractToDirectory ( source As ZipArchive, destinationDirectoryName As String )
The zip archive to extract files from.
The path to the directory to place the extracted files in. You can specify either a relative or an absolute path. A relative path is interpreted as relative to the current working directory.
destinationDirectoryName is Empty, contains only white space, or contains at least one invalid character.
destinationDirectoryName is null.
The specified path exceeds the system-defined maximum length. For example, on Windows-based platforms, paths must not exceed 248 characters, and file names must not exceed 260 characters.
The specified path is invalid (for example, it is on an unmapped drive).
The directory specified by destinationDirectoryName already exists.
The name of an entry in the archive is Empty, contains only white space, or contains at least one invalid character.
Extracting an entry from the archive 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.)
Two or more entries in the archive have the same name.
The caller does not have the required permission to write to the destination directory.
destinationDirectoryName contains an invalid format.
An archive entry cannot be found or is corrupt.
An archive entry was compressed by using a compression method that is not supported.
This method creates the directory specified by destinationDirectoryName. If the destination directory already exists, this method does not overwrite it; it throws an IOException exception. The method also creates subdirectories that reflect the hierarchy in the zip archive. 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.
The following example shows how to create a new entry in a zip archive from an existing file, and extract the archive to a new directory. In order to compiler this code example, you must reference the System.IO.Compression and System.IO.Compression.FileSystem assemblies in your project.
Imports System.IO Imports System.IO.Compression Module Module1 Sub Main() Dim zipPath As String = "c:\users\exampleuser\end.zip" Dim extractPath As String = "c:\users\exampleuser\extract" Dim newFile As String = "c:\users\exampleuser\NewFile.txt" Using archive As ZipArchive = ZipFile.Open(zipPath, ZipArchiveMode.Update) archive.CreateEntryFromFile(newFile, "NewEntry.txt", CompressionLevel.Fastest) archive.ExtractToDirectory(extractPath) End Using End Sub End Module
Available since 10
Available since 4.5