ZipFile Class
![]() |
---|
The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience. |
Provides static methods for creating, extracting, and opening zip archives.
Assembly: Â System.IO.Compression.FileSystem (in System.IO.Compression.FileSystem.dll)
Name | Description | |
---|---|---|
![]() ![]() | CreateFromDirectory(String, String) | Creates a zip archive that contains the files and directories from the specified directory. |
![]() ![]() | CreateFromDirectory(String, String, CompressionLevel, Boolean) | Creates a zip archive that contains the files and directories from the specified directory, uses the specified compression level, and optionally includes the base directory. |
![]() ![]() | CreateFromDirectory(String, String, CompressionLevel, Boolean, Encoding) | Creates a zip archive that contains the files and directories from the specified directory, uses the specified compression level and character encoding for entry names, and optionally includes the base directory. |
![]() ![]() | ExtractToDirectory(String, String) | Extracts all the files in the specified zip archive to a directory on the file system. |
![]() ![]() | ExtractToDirectory(String, String, Encoding) | Extracts all the files in the specified zip archive to a directory on the file system and uses the specified character encoding for entry names. |
![]() ![]() | Open(String, ZipArchiveMode) | Opens a zip archive at the specified path and in the specified mode. |
![]() ![]() | Open(String, ZipArchiveMode, Encoding) | Opens a zip archive at the specified path, in the specified mode, and by using the specified character encoding for entry names. |
![]() ![]() | OpenRead(String) | Opens a zip archive for reading at the specified path. |
![]() |
---|
To use the ZipFile class, you must add a reference to the System.IO.Compression.FileSystem assembly in your project; otherwise, you'll get the following error message when trying to compile : The name 'ZipFile' does not exist in the current context. For more information on how to add a reference to your project in Visual Studio, see How to: Add or Remove References By Using the Reference Manager. |
The methods for manipulating zip archives and their files are spread across three classes: ZipFile, ZipArchive and ZipArchiveEntry.
To… | Use… |
---|---|
Create a zip archive from a directory | |
Extract the contents of a zip archive to a directory | |
Add new files to an existing zip archive | |
Retrieve an file in a zip archive | |
Retrieve all of the files in a zip archive | |
To open a stream to an individual file contained in a zip archive | |
Delete a file from a zip archive |
You cannot use the ZipFile or ZipFileExtensions classes in Windows 8.x Store apps. In Windows 8.x Store apps, you should use the following classes to work with compressed files.
This example shows how to create and extract a zip archive by using the ZipFile class. It compresses the contents of a folder into a zip archive, and then extracts that content to a new folder.
![]() |
---|
To use the ZipFile class, you must reference the System.IO.Compression.FileSystem assembly in your project. |
using System; using System.IO; using System.IO.Compression; namespace ConsoleApplication { class Program { static void Main(string[] args) { string startPath = @"c:\example\start"; string zipPath = @"c:\example\result.zip"; string extractPath = @"c:\example\extract"; ZipFile.CreateFromDirectory(startPath, zipPath); ZipFile.ExtractToDirectory(zipPath, extractPath); } } }
Available since 10
.NET Framework
Available since 4.5
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.