Export (0) Print
Expand All

ZipArchive Class

.NET Framework 4.5

Represents a package of compressed files in the zip archive format.

System.Object
  System.IO.Compression.ZipArchive

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

type ZipArchive =  
    class 
        interface IDisposable 
    end

The ZipArchive type exposes the following members.

  NameDescription
Public methodSupported in .NET for Windows Store appsZipArchive(Stream)Initializes a new instance of the ZipArchive class from the specified stream.
Public methodSupported in .NET for Windows Store appsZipArchive(Stream, ZipArchiveMode)Initializes a new instance of the ZipArchive class from the specified stream and with the specified mode.
Public methodSupported in .NET for Windows Store appsZipArchive(Stream, ZipArchiveMode, Boolean)Initializes a new instance of the ZipArchive class on the specified stream for the specified mode, and optionally leaves the stream open.
Public methodSupported in .NET for Windows Store appsZipArchive(Stream, ZipArchiveMode, Boolean, Encoding)Initializes a new instance of the ZipArchive class on the specified stream for the specified mode, uses the specified encoding for entry names, and optionally leaves the stream open.
Top

  NameDescription
Public propertySupported in .NET for Windows Store appsEntriesGets the collection of entries that are currently in the zip archive.
Public propertySupported in .NET for Windows Store appsModeGets a value that describes the type of action the zip archive can perform on entries.
Top

  NameDescription
Public methodSupported in .NET for Windows Store appsCreateEntry(String)Creates an empty entry that has the specified path and entry name in the zip archive.
Public methodSupported in .NET for Windows Store appsCreateEntry(String, CompressionLevel)Creates an empty entry that has the specified entry name and compression level in the zip archive.
Public methodSupported in .NET for Windows Store appsDispose()Releases the resources used by the current instance of the ZipArchive class.
Protected methodSupported in .NET for Windows Store appsDispose(Boolean)Called by the Dispose() and Finalize() methods to release the unmanaged resources used by the current instance of the ZipArchive class, and optionally finishes writing the archive and releases the managed resources.
Public methodSupported in .NET for Windows Store appsEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodSupported in .NET for Windows Store appsFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported in .NET for Windows Store appsGetEntryRetrieves a wrapper for the specified entry in the zip archive.
Public methodSupported in .NET for Windows Store appsGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported in .NET for Windows Store appsMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported in .NET for Windows Store appsToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public Extension MethodCreateEntryFromFile(String, String)Overloaded. Archives a file by compressing it and adding it to the zip archive. (Defined by ZipFileExtensions.)
Public Extension MethodCreateEntryFromFile(String, String, CompressionLevel)Overloaded. Archives a file by compressing it using the specified compression level and adding it to the zip archive. (Defined by ZipFileExtensions.)
Public Extension MethodExtractToDirectoryExtracts all the files in the zip archive to a directory on the file system. (Defined by ZipFileExtensions.)
Top

The ZipArchive class enables you to work with a package of compressed files. The package contains an entry for each compressed file. You can:

  • Retrieve an entry by using the GetEntry method.

  • Retrieve the entire collection of entries by using the Entries property.

  • Create a new entry in the package by calling the overloaded CreateEntry method.

For static methods to create a zip archive from a directory or extract a zip archive to a directory, see the ZipFile class.

When you create a new entry, the file is compressed and added to the zip package. The CreateEntry method enables you to specify a directory hierarchy when adding the entry. You include the relative path of the new entry within the zip package. For example, creating a new entry with a relative path of AddedFolder\NewFile.txt creates a compressed text file in a directory named AddedFolder.

If you reference the System.IO.Compression.FileSystem assembly in your project, you can access three extension methods (from the ZipFileExtensions class) for the ZipArchive class: CreateEntryFromFile, CreateEntryFromFile, and ExtractToDirectory. These extension methods enable you to compress and decompress the contents of the entry to a file. The System.IO.Compression.FileSystem assembly is not available for Windows Store apps. In Windows Store apps, you can compress and decompress files by using the DeflateStream or GZipStream class, or you can use the Windows Runtime types Compressor and Decompressor.

The first example shows how to create a new entry and write to it by using a stream.

No code example is currently available or this language may not be supported.

The following example shows how to open a zip archive and iterate through the collection of entries.

No code example is currently available or this language may not be supported.

The third example shows how to use extension methods to create a new entry in a zip archive from an existing file and extract the archive contents. You must reference the System.IO.Compression.FileSystem assembly to execute the code.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1

Windows Phone 8.1, 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.
Show:
© 2014 Microsoft