0

I am currently working on a web project where the user can upload files freely by clicking on a link (a href tag) :

textHTML.Append("<a href='download.aspx?file=" + PathFile[i] + "' title='" + Title[i] + " (" + fileType + ", " + fileSize + ")" + "'>" + _Download + " <font color=\"#999999\">(" + Language[i] + ")</font></a>");

in the download.aspx page:

Response.ContentType = "Application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Request["file"]);
Response.TransmitFile("../../img/content/csr_dc_documents/" + Request["file"]);
Response.End();

I'm trying to find the best solution to offer the user to download as much as files he wants at the same time

So my question is the following: is it possible to create a zip folder containing all the files he selects ? and this without saving anything in the server? Thanks in advance for your advises

  • You can check out the `ZipFile` or `ZipArchive` classes to determine what method works best for you. You will need to create the file locally and once the download is complete you could remove the file. – KSdev Feb 20 '14 at 21:06
  • @KSdev, for the record, this is only in 4.0 framework and higher. You will need to use a 3rd party library or your own code with .net 3.5 or lower. – gunr2171 Feb 20 '14 at 21:15
  • @gunr2171 Very good point. I actually run in 3.5 for one of my main GUI, so I know the pain. IF you are not able to use the aforementioned check out this previous [**question**](http://stackoverflow.com/questions/593026/is-there-a-built-in-zip-library-in-net-3-5) where a library for 3.5 is discussed. – KSdev Feb 20 '14 at 21:16
  • 1
    If you're using .NET 4.0 or later, you can create a [ZipArchive](http://msdn.microsoft.com/en-us/library/system.io.compression.ziparchive%28v=vs.110%29.aspx) in a `MemoryStream`, and then send the contents of that stream to the user. All without accessing the file system. Implementation is left as an exercise. – Jim Mischel Feb 20 '14 at 22:09

1 Answers1

0

If you are using the .Net 4.5 framework, you can create a zip archive of any and all the files you desire by using the System.IO.Compression ZipFile or ZipArchive classes. See MSDN System.IO.Compression for all the details. Several examples are posted throughout the material on how to create zip archives, add entries, and extract entries and the entire archive.

StarPilot
  • 2,246
  • 1
  • 16
  • 18