This is an ASPX file that shows how to use DotNetZip in an ASP.NET page, in C#. For a VB.NET Example see here.

<%@ Page 
    Debug="true" %>

<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="Ionic.Zip" %>
<%@ Import Namespace="System.Collections.Generic" %>

<script language="C#" runat="server">

// ZipExample.aspx 
// This .aspx page demonstrates how to use the DotNetZip library from within ASP.NET.
// To run it, 
//  1. drop the Ionic.Zip.dll into the \bin directory of yoru app
//  2. create a subdirectory called "fodder" in your web app directory.
//  3. copy into that directory a variety of random files.
//  4. insure your web.config is properly set up (See below)
// notes:
//  This requies the .NET Framework 3.5 - because it uses the ListView control that is 
//  new for ASP.NET in the .NET Framework v3.5.  
//  To use this control, you must add the new web controls.  Also, you must use the v3.5 compiler. 
//  Here's an example web.config that works with this aspx file: 
//    <configuration>
//      <system.web>
//        <trust level="Medium" />
//        <compilation defaultLanguage="c#" />
//        <pages>
//          <controls>
//            <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
//          </controls>
//        </pages>
//      </system.web>
//      <system.codedom>
//        <compilers>
//          <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089">
//            <providerOption name="CompilerVersion" value="v3.5" />
//            <providerOption name="WarnAsError" value="false" />
//          </compiler>
//        </compilers>
//      </system.codedom>
//    </configuration>
// If you use medium trust, then you will need v1.6 of DotNetZip, at a minimum.

public String width = "100%";

public void Page_Load (Object sender, EventArgs e)
        if ( !Page.IsPostBack ) {
            // populate the dropdownlist
            // must have a directory called "fodder" in the web app 
            String sMappedPath= Server.MapPath("fodder");
            var fqFilenames= new List<String>(System.IO.Directory.GetFiles(sMappedPath));
            var filenames= fqFilenames.ConvertAll((s) => { return s.Replace(sMappedPath+"\\", ""); });

            ErrorMessage.InnerHtml = "";

            FileListView.DataSource = filenames;

    catch (Exception) 
        // Ignored

public void btnGo_Click (Object sender, EventArgs e)
    ErrorMessage.InnerHtml ="";   // debugging only
    var filesToInclude= new System.Collections.Generic.List<String>();
    String sMappedPath= Server.MapPath("fodder");
    var source= FileListView.DataKeys as DataKeyArray ;

    foreach (var item in  FileListView.Items) 
        CheckBox chkbox= item.FindControl("include") as CheckBox ;
        Label lbl= item.FindControl("label") as Label ;

        if (chkbox!=null  && lbl != null)
            if (chkbox.Checked)
                ErrorMessage.InnerHtml += String.Format("adding file: {0}<br/>\n", lbl.Text);


    if (filesToInclude.Count==0)
        ErrorMessage.InnerHtml += "You did not select any files?<br/>\n";


        System.Web.HttpContext c= System.Web.HttpContext.Current;
        String ReadmeText= String.Format("README.TXT\n\nHello!\n\nThis is a zip file that was dynamically generated at {0}\nby an ASP.NET Page running on the machine named '{1}'.\nThe server type is: {2}\n", 
        string archiveName= String.Format("archive-{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss")); 
        Response.ContentType = "application/zip";
        Response.AddHeader("content-disposition", "attachment; filename=" + archiveName);
        using (ZipFile zip = new ZipFile())
            // filesToInclude is a string[] or List<string>
            zip.AddFiles(filesToInclude, "files");
            zip.AddFileFromString("Readme.txt", "", ReadmeText);



    <link rel="stylesheet" href="style/basic.css">


    <form id="Form" runat="server">

      <h3> <span id="Title" runat="server" />Zip Files from ASP.NET </h3>

      <p>This page uses the .NET Zip library 
      (see <a href=""></a>) 
       to dynamically create a zip archive, and then download it to the browser through 
       Response.OutputStream.  This page is implemented in C#</p>

      <span class="SampleTitle"><b>Check the boxes to select the files, then click the button to zip them up.</b></span>
      <asp:Button id="btnGo" Text="Zip checked files" AutoPostBack OnClick="btnGo_Click" runat="server"/>
      <span style="color:red" id="ErrorMessage" runat="server"/>

      <asp:ListView ID="FileListView" runat="server">

            <tr ID="itemPlaceholder" runat="server" />

            <td><asp:Checkbox ID="include" runat="server"/></td>
            <td><asp:Label id="label" runat="server" Text="<%# Container.DataItem %>" /></td>

          <div>Nothing to see here...</div>





Last edited Oct 29, 2009 at 12:57 PM by Cheeso, version 13


Trisped Mar 6, 2013 at 10:48 PM 
@destryalhmns Simple examples using C# can currently be found at . This page is showing a complete ASP.NET example.

The clearest example which answers your question is "Add an entry, getting content from a string.", just replace `content` with your byte[], or you can use one of the other overloads of `AddEntry`. If you want to daisy chain the compressed result to a stream then change the `ZipFile` class to `ZipOutputStream`.

You can also check the reference at if you need more help.

GollyGee Jan 21, 2013 at 4:31 PM 
destryalhmns: I hope you enjoy your career in whatever it is other than programming.

destryalhmns Feb 25, 2012 at 3:36 PM 
I went through the trouble of creating an account just so I could say this.

Nobody needs a ton of code to sort through and no one wants to sort through it only to find out it's not helpful. Look at all of that code.... we just need simple one liners that explain how to make Ionic do basic stuff..... turn and uploaded byte[] into a zipfile for example. This should be easy crap that I hate spending forever trying to figure out.

aleksas85 Apr 22, 2009 at 2:34 PM 
How about opening existing archive as stream and updating it?
Opening zip using read function and then saving messes up file permittions. In my case zip is created under unix containing some files with appropriate permutations later I need to add more files under Windows.