Zip Samples - icsharpcode/SharpZipLib GitHub Wiki

Code Reference / Zip Samples

How to use SharpZipLib to work with Zip files

These samples try to cover the range of situations you will encounter. You may need to combine parts of each sample for your application.

General usage

Specific usage

Short examples

Create a Zip from a HTML string (C#)

string htmlData = ...

using (var fs = File.Create("html-archive.zip"))
using (var outStream = new ZipOutputStream(fs))
{
    outStream.PutNextEntry(new ZipEntry("content.html"));

    using (var sw = new StreamWriter(outStream))
    {
            sw.Write(htmlData);
    }
}

Create a Zip from a byte array (C#)

var dataBytes = new byte[] { 0x49, 0xe2, 0x9d, 0xa4, 0x5a, 0x49, 0x50 };

using (var fs = File.Create("data.zip"))
using (var outStream = new ZipOutputStream(fs))
{
    outStream.PutNextEntry(new ZipEntry("data.bin"));
    outStream.Write(dataBytes);
}