Zip files on the server

How can I fix (on the server) several files in one archive?

+3
source share
3 answers

The following code uses our Rebex ZIP and shows how to add files to a ZIP archive without using a temporary file. Then the ZIP is sent to the web browser.

// prepare MemoryStream to create ZIP archive within
using (MemoryStream ms = new MemoryStream())
{
    // create new ZIP archive within prepared MemoryStream
    using (ZipArchive zip = new ZipArchive(ms))
    {            
         // add some files to ZIP archive
         zip.Add(@"c:\temp\testfile.txt");
         zip.Add(@"c:\temp\innerfile.txt", @"\subfolder");

         // clear response stream and set the response header and content type
         Response.Clear();
         Response.ContentType = "application/zip";
         Response.AddHeader("content-disposition", "filename=sample.zip");

         // write content of the MemoryStream (created ZIP archive) 
         // to the response stream
         ms.WriteTo(Response.OutputStream);
    }
}

// close the current HTTP response and stop executing this page
HttpContext.Current.ApplicationInstance.CompleteRequest();

See the ZIP tutorial for more information .

Alternative solution:

SharpZipLib and DotNetZip made extensive use of free alternatives.

+2
source

Take a look at SharpZipLib or DotNetZip

+1
source

Codeplex Dot Net Zip http://dotnetzip.codeplex.com/

System.IO.Compression

0

Source: https://habr.com/ru/post/1765629/


All Articles