Export (0) Print
Expand All

ZipArchive Constructor (Stream, ZipArchiveMode, Boolean, Encoding)

.NET Framework 4.5

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.

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

public ZipArchive(
	Stream stream,
	ZipArchiveMode mode,
	bool leaveOpen,
	Encoding entryNameEncoding
)

Parameters

stream
Type: System.IO.Stream

The input or output stream.

mode
Type: System.IO.Compression.ZipArchiveMode

One of the enumeration values that indicates whether the zip archive is used to read, create, or update entries.

leaveOpen
Type: System.Boolean

true to leave the stream open after the ZipArchive object is disposed; otherwise, false.

entryNameEncoding
Type: System.Text.Encoding

The encoding to use when reading or writing entry names in this archive. Specify a value for this parameter only when an encoding is required for interoperability with zip archive tools and libraries that do not support UTF-8 encoding for entry names.

ExceptionCondition
ArgumentException

The stream is already closed, or the capabilities of the stream do not match the mode.

ArgumentNullException

stream is null.

ArgumentOutOfRangeException

mode is an invalid value.

InvalidDataException

The contents of the stream could not be interpreted as a zip archive.

-or-

mode is Update and an entry is missing from the archive or is corrupt and cannot be read.

-or-

mode is Update and an entry is too large to fit into memory.

If the mode parameter is set to Read, the stream must support reading. If the mode parameter is set to Create, the stream must support writing. If the mode parameter is set to Update, the stream must support reading, writing, and seeking.

When you open a zip archive file for reading and entryNameEncoding is set to null, entry names are decoded according to the following rules:

  • When the language encoding flag (in the general-purpose bit flag of the local file header) is not set, the current system default code page is used to decode the entry name.

  • When the language encoding flag is set, UTF-8 is used to decode the entry name.

When you open a zip archive file for reading and entryNameEncoding is set to a value other than null, entry names are decoded according to the following rules:

  • When the language encoding flag is not set, the specified entryNameEncoding is used to decode the entry name.

  • When the language encoding flag is set, UTF-8 is used to decode the entry name.

When you write to archive files and entryNameEncoding is set to null, entry names are encoded according to the following rules:

  • For entry names that contain characters outside the ASCII range, the language encoding flag is set, and entry names are encoded by using UTF-8.

  • For entry names that contain only ASCII characters, the language encoding flag is not set, and entry names are encoded by using the current system default code page.

When you write to archive files and entryNameEncoding is set to a value other than null, the specified entryNameEncoding is used to encode the entry names into bytes. The language encoding flag (in the general-purpose bit flag of the local file header) is set only when the specified encoding is a UTF-8 encoding.

.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.

Show:
© 2014 Microsoft