Re: Compress files during upload.

  •  11-21-2008, 10:27 AM

    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
View Complete Thread