Compress files during upload.

Last post 11-26-2008, 5:13 AM by Allen99. 2 replies.
Sort Posts: Previous Next
  •  11-20-2008, 10:39 PM 46044

    Compress files during upload.

    Hi there,
     
    I uploaded some files to server and listed them all, each file is a link and can be downloaded via a download.ashx file. But need to click them one by one to download them all. Is there a way to download them all once by compress all them into a zip file? I remembered there is a example of that here using a  zip dll but cannot find it any longer.
     
    Thanks.
     
    Allen.
  •  11-21-2008, 10:27 AM 46141 in reply to 46044

    Re: Compress files during upload.

    Allen,
     
    You can download the  http://www.codeplex.com/DotNetZip
     
    and then try this code :
     
     

    <%@ Page Language="C#" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

     protected void ButtonDownload_Click(object sender, EventArgs e)
     {
      if (Uploader1.Items.Count == 0)
       return;

      Context.Response.Clear();
      Context.Response.AddHeader("Content-Disposition", "attachment; filename=allfiles.zip");
      
      Ionic.Utils.Zip.ZipFile file = new Ionic.Utils.Zip.ZipFile(Response.OutputStream);
      foreach (AttachmentItem item in Uploader1.Items)
      {
       if (!item.Visible) continue;
       if (!item.Checked) continue;
       
       file.AddFileStream(item.FileName, "", item.OpenStream());
      }
      file.Save();

      Context.Response.End();
     }
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
     <title>Untitled Page</title>
    </head>
    <body>
     <form id="form1" runat="server">
      <CuteWebUI:UploadAttachments runat="server" ID="Uploader1" />
      <br />
      <asp:Button runat="server" ID="ButtonDownload" Text="DownloadAll" OnClick="ButtonDownload_Click" />
     </form>
    </body>
    </html>

     
    Regards,
    Terry
  •  11-26-2008, 5:13 AM 46306 in reply to 46044

    Re: Compress files during upload.

    It works perfect!
     
    Thanks for that.
     
    Allen.
     
     
View as RSS news feed in XML