ZipFile Class

.NET Framework 4.5

Provides static methods for creating, extracting, and opening zip archives.

System.Object
  System.IO.Compression.ZipFile

Namespace:  System.IO.Compression
Assembly:  System.IO.Compression.FileSystem (in System.IO.Compression.FileSystem.dll)

public static class ZipFile

The ZipFile type exposes the following members.

  NameDescription
Public methodStatic memberCreateFromDirectory(String, String)Creates a zip archive that contains the files and directories from the specified directory.
Public methodStatic memberCreateFromDirectory(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.
Public methodStatic memberCreateFromDirectory(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.
Public methodStatic memberExtractToDirectory(String, String)Extracts all the files in the specified zip archive to a directory on the file system.
Public methodStatic memberExtractToDirectory(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.
Public methodStatic memberOpen(String, ZipArchiveMode)Opens a zip archive at the specified path and in the specified mode.
Public methodStatic memberOpen(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.
Public methodStatic memberOpenReadOpens a zip archive for reading at the specified path.
Top

Important noteImportant

To use the ZipFile class, you must add a reference to the System.IO.Compression.FileSystem assembly in your project. You cannot use this class in Windows Store apps.

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

ZipFile.CreateFromDirectory

Extract the contents of a zip archive to a directory

ZipFile.ExtractToDirectory

Add new files to an existing zip archive

ZipArchive.CreateEntry

Retrieve an file in a zip archive

ZipArchive.GetEntry

Retrieve all of the files in a zip archive

ZipArchive.Entries

To open a stream to an individual file contained in a zip archive

ZipArchiveEntry.Open

Delete a file from a zip archive

ZipArchiveEntry.Delete

You cannot use the ZipFile or ZipFileExtensions classes in Windows Store apps. In Windows 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);
        }
    }
}

.NET Framework

Supported in: 4.6, 4.5

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft