AlternateEncoding Property

DotNetZip

Ionic Zip Library v1.9.1.6 AlternateEncoding Property
ReferenceIonic.ZipZipEntryAlternateEncoding
Specifies the alternate text encoding used by this ZipEntry
Declaration Syntax
C# Visual Basic Visual C++
public Encoding AlternateEncoding { get; set; }
Public Property AlternateEncoding As Encoding
	Get
	Set
public:
property Encoding^ AlternateEncoding {
	Encoding^ get ();
	void set (Encoding^ value);
}
Remarks

The default text encoding used in Zip files for encoding filenames and comments is IBM437, which is something like a superset of ASCII. In cases where this is insufficient, applications can specify an alternate encoding.

When creating a zip file, the usage of the alternate encoding is governed by the AlternateEncodingUsage property. Typically you would set both properties to tell DotNetZip to employ an encoding that is not IBM437 in the zipfile you are creating.

Keep in mind that because the ZIP specification states that the only valid encodings to use are IBM437 and UTF-8, if you use something other than that, then zip tools and libraries may not be able to successfully read the zip archive you generate.

The zip specification states that applications should presume that IBM437 is in use, except when a special bit is set, which indicates UTF-8. There is no way to specify an arbitrary code page, within the zip file itself. When you create a zip file encoded with gb2312 or ibm861 or anything other than IBM437 or UTF-8, then the application that reads the zip file needs to "know" which code page to use. In some cases, the code page used when reading is chosen implicitly. For example, WinRar uses the ambient code page for the host desktop operating system. The pitfall here is that if you create a zip in Copenhagen and send it to Tokyo, the reader of the zipfile may not be able to decode successfully.

Examples
This example shows how to create a zipfile encoded with a language-specific encoding:
CopyC#
using (var zip = new ZipFile())
{
   zip.AlternateEnoding = System.Text.Encoding.GetEncoding("ibm861");
   zip.AlternateEnodingUsage = ZipOption.Always;
   zip.AddFileS(arrayOfFiles);
   zip.Save("Myarchive-Encoded-in-IBM861.zip");
}

Assembly: Ionic.Zip (Module: Ionic.Zip) Version: 1.9.1.8 (1.9.1.8)