Skip to content

Create & Download zip file from remote directory using C#

Sathish Kumar

Sathish Kumar

Asked Jan 29, 2016, 2:55 AM EST1 answer
Share
LinkedInX
Hi All,
 
         In my web application, I wanna check the given directory  is exist in remote location,
         if it exists then compress that directory into zip and download in browser. How can i achieve this. 
 
 
 
Thanks in Advance 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Ben Tomas
    0

    You should create HTML and then create a zip file like:

    C#
    using(ZipFile file = new ZipFile()) { file.AddEntry(''myHtml''+'''.html',''generatedHtml''); file.AddEntry(''myXml''+'''.xml',''generatedXml''); file.AddEntry(''myText''+'''.txt',''generatedTxt'');  Response.ClearContent();Response.ClearHeaders(); Response.AppendHeader("content-disposition","attachment;filename=Report.zip");             file.Save(Response.OutputStream); }

    and then saving the zip file on output stream. It's working fine, ZipFile download option pops up in the browser and is downloaded wherever user saves it like:

    Code
    Report.zip-> myHtml,myXml,myText
    Code
    Regards,
    Code
    Ben - developr from web application development company - http://www.iflexion.com/
    0