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.
static void Main(string args)
string startPath = @".\start";
string zipPath = @".\result.zip";
string extractPath = @".\extract";
Dim startPath As String = ".\start"
Dim zipPath As String = ".\result.zip"
Dim extractPath As String = ".\extract"
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.
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.