0

I have an ASP.NET Web Forms application. Once the user clicks on a download link, I need to create several XMLs file on the fly, zip them and prompt the user with a download dialog.

I already made the function to download a single XML file and it works correctly. The link in the download.aspx file is:

<asp:HyperLink ID="hlDownload" Text="Download" NavigateUrl='<%# String.Format("GetFile.aspx?LicenseGuid={0}", Eval("ProductId")) %>' runat="server"></asp:HyperLink>

The function in the GetFile.aspx code behind:

Dim xmlFile = _productServices.GetXMLFilePerProductId(ProductId)
Dim xdoc As XmlDocument = New XmlDocument()
xdoc.LoadXml(xmlFile)

Response.Clear()
Response.ContentType = "text/xml"
Response.ContentEncoding = System.Text.Encoding.UTF8
Response.AddHeader("Content-Disposition", "attachment; filename=some_name.xml")

xdoc.Save(Response.Output)
Response.End()

How can I create a ZIP file on the fly and pack a couple of XML files, created on the fly as well?

PS: answers in both C# and VB.NET are welcome

CiccioMiami
  • 7,439
  • 28
  • 82
  • 145
  • We don't give teh codez here - you have been around long enough to know this. Please explain [what you have tried](http://whathaveyoutried.com) and where you are stuck. – Oded Sep 06 '12 at 09:34
  • Sorry, I know SO policy, I didn't want the code, just an overview of the process that I have to follow in order to implement the function. At the moment I was able to create a ZIP file, just starting from file created and saved in the HD – CiccioMiami Sep 06 '12 at 09:39

2 Answers2

2

You can use the ZipFile class of the CodeFluent Entities Runtime Client package : Link here

This library allows the use of streams only, meaning that you don't have a create a temporary file on the filesystem.

Bgi
  • 2,505
  • 10
  • 11
2

If you like you can go for .net GZip or Deflate streams and can develop a solution of your own or A better option is to use SharpZip .net Library, that has managed Code.

Furqan Hameedi
  • 4,292
  • 3
  • 23
  • 34
  • Thanks! Why do you think the SharpZip is a better library? – CiccioMiami Sep 06 '12 at 09:40
  • @CiccioMiami, its open source, well tested and provide a quick API to acheive what you desire. – Furqan Hameedi Sep 06 '12 at 09:44
  • SharpZipLib is slow "For CPU performance and memory usage reasons, and contrary to other popular .NET zip implementations (http://www.icsharpcode.net/opensource/sharpziplib/, or http://dotnetzip.codeplex.com/), CodeFluent Entities’ ZipFile implementation is unmanaged." – Bgi Sep 06 '12 at 09:46
  • @Bgi SharpZip is the popular `icsharpcode.net/opensource/sharpziplib` – Furqan Hameedi Sep 06 '12 at 09:49