This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Download Microsoft Edge
More info about Internet Explorer and Microsoft Edge
To use the
ZipFile
class in a .NET Framework app, you must add a reference to the
System.IO.Compression.FileSystem
assembly in your project. For information on how to add a reference to your project in Visual Studio, see
How to: Add or Remove References
.
The methods for manipulating zip archives and their files are spread across three classes:
ZipFile
,
ZipArchive
, and
ZipArchiveEntry
.
To...
Use...
Examples
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.
using System;
using System.IO.Compression;
class Program
static void Main(string[] args)
string startPath = @".\start";
string zipPath = @".\result.zip";
string extractPath = @".\extract";
ZipFile.CreateFromDirectory(startPath, zipPath);
ZipFile.ExtractToDirectory(zipPath, extractPath);
Imports System.IO.Compression
Module Module1
Sub Main()
Dim startPath As String = ".\start"
Dim zipPath As String = ".\result.zip"
Dim extractPath As String = ".\extract"
ZipFile.CreateFromDirectory(startPath, zipPath)
ZipFile.ExtractToDirectory(zipPath, extractPath)
End Sub
End Module