Downloading Zipfile >280mB fails

Jul 30, 2010 at 12:48 PM
Edited Jul 30, 2010 at 10:43 PM

Hi there, I am having problems with downloading dynamically created zip files which are bigger than 280mB. I have based my code on your example "ASP.NET Example in VB" example (, but I have changed the code to save the file to disk, then enable a user to download it. In my code, downloading a zipped file >280mB fails, while smaller files work. This occurs on my dev machine, as well as on a Rackspace Cloud Server where my app is hosted. If I place a link to a large zip file, it downloads without a hitch. (e.g. 166kB )

I was wondering if there is a limitation on downloading large files, a setting that needs tweaking, or if there is an error in my code/logic. Here is my code. Also, if you require, I can send a link to the server where this page is hosted.

 Any help will be gratefully appreciated.

Thanks in advance,

Rob Nagel

Code: (I changed the folder "fodder" to "zipfiles")

<%@ Page

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

<script language="VB" 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>
'          <compiler language="vb;vbs;visualbasic;vbscript"
'                    extension=".vb"
'                    warningLevel="4"
'                    type="Microsoft.VisualBasic.VBCodeProvider, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089">
'            <providerOption name="CompilerVersion" value="v3.5" />
'            <providerOption name="OptionInfer" value="false" />
'            <providerOption name="WarnAsError" value="false" />
'          </compiler>
'      </system.codedom>
'    </configuration>

Dim width as String = "100%"

Public Sub Page_Load (ByVal sender As Object, ByVal e As System.EventArgs)


        If Not ( Page.IsPostBack ) Then
            ' populate the dropdownlist
            ' must have a directory called "fodder" in the web app
                Dim sMappedPath As String = Server.MapPath("zipfiles")
            Dim fqFilenames As New List(Of String)(System.IO.Directory.GetFiles(sMappedPath))

                Dim filenames As List(Of String) = fqFilenames.ConvertAll(Function(s) s.Replace(sMappedPath & "\", ""))

            ErrorMessage.InnerHtml = ""
            FileListView.DataSource = filenames
        End If


        ' Ignored
    End Try

End Sub


Public Sub btnGo_Click (ByVal sender As System.Object, ByVal e As System.EventArgs)

    ErrorMessage.InnerHtml =""   ' debugging only
    Dim filesToInclude as New System.Collections.Generic.List(Of String)()
        Dim sMappedPath As String = Server.MapPath("zipfiles")
    Dim source As DataKeyArray= FileListView.DataKeys

    For Each item As ListViewDataItem in FileListView.Items

        Dim chkbox As CheckBox= CType(item.FindControl("include"), CheckBox)
        Dim lbl As Label = CType(item.FindControl("label"), Label)

        If Not (chkbox Is Nothing  OR  lbl Is Nothing) Then
            If (chkbox.Checked) Then
                ErrorMessage.InnerHtml = ErrorMessage.InnerHtml & _
                        String.Format("adding file: {0}<br/>\n", lbl.Text)
            End If
        End If

    If (filesToInclude.Count=0) Then

        ErrorMessage.InnerHtml = ErrorMessage.InnerHtml & "You did not select any files?<br/>\n"


        Response.BufferOutput= false

        Dim enc as Ionic.Zip.EncryptionAlgorithm = Ionic.Zip.EncryptionAlgorithm.None
        If (chkUseAes.Checked) Then
            enc = EncryptionAlgorithm.WinZipAes256
        End If

 Dim c As System.Web.HttpContext = System.Web.HttpContext.Current
        Dim ReadmeText As  String= String.Format("README.TXT\n\nHello!\n\n" & _
                                         "This is a zip file that was dynamically generated at {0}\n" & _
                                         "by an ASP.NET Page running on the machine named '{1}'.\n" & _
                                         "The server type is: {2}\n" & _
                                         "The password used: {3}\n", _
                                         "Encryption: {4}\n", _
                                         System.DateTime.Now.ToString("G"), _
                                         System.Environment.MachineName, _
                                         c.Request.ServerVariables("SERVER_SOFTWARE"), _
                                         tbPassword.Text, _
                                         enc.ToString )
        Dim archiveName as String= String.Format("archive-{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"))
        Response.ContentType = "application/zip"
        Response.AddHeader("content-disposition", "filename=" + archiveName)
        Using zip as new ZipFile()
            ' the Readme.txt file will not be password-protected.
                'zip.AddEntry("Readme.txt", "", ReadmeText, Encoding.Default)
            If Not String.IsNullOrEmpty(tbPassword.Text) Then
                zip.Password = tbPassword.Text
                zip.Encryption = enc
            End If
            ' filesToInclude is a string[] or List<String>
            zip.AddFiles(filesToInclude, "files")
                zip.Save(sMappedPath & "\" & archiveName)
            End Using
            Dim file As System.IO.FileInfo = New System.IO.FileInfo(sMappedPath & "\" & archiveName) '-- if the file exists on the server
            Response.ContentType = "application/zip"
            Response.AddHeader("Content-Disposition", "attachment; filename=" & file.Name)
            Response.AddHeader("Content-Length", file.Length.ToString())
            Response.End() 'if file does not exist 

    End If

End Sub



    <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
      to dynamically create a zip archive, and then download it to the
      browser through Response.OutputStream.  This page is implemented
      in VB.NET.</p>

      <span class="SampleTitle"><b>Check the boxes to select the files, set a password if you like,
      then click the button to zip them up.</b></span>
      Password: <asp:TextBox id="tbPassword" Password='true' Text="" AutoPostBack runat="server"/>
      <span style="color:Red">(Optional)</span>
      Use AES?: <asp:CheckBox id="chkUseAes" AutoPostBack runat="server"/>
      <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>


      <br />
      <a href=""></a>
      <br /><a href="/zipfiles/"> 166kB</a>
      <br /><a href="/zipfiles/"> 122 Mb</a>
      <br /><a href="/zipfiles/"> 284 Mb</a>