[
  {
    "Id": "209583",
    "ThreadId": "61753",
    "Html": "<p>I recently upgraded to version 1.8 from 1.6 and this code no longer works for creating a new zip file into the Output Stream:</p>\r\n<p><span style=\"color:#0000ff\">ZipFile zip = new ZipFile(Response.OutputStream)</span></p>\r\n<p>I get the error:</p>\r\n<p><span style=\"color:#0000ff\">Cannot resolve constructor 'ZipFile(System.IO.Stream)', candidates are:</span></p>\r\n<p><span style=\"color:#0000ff\">ZipFile(string) (in class ZipFile)</span></p>\r\n<p><span style=\"color:#0000ff\">ZipFile(System.Text.Encoding) (in class ZipFile)</span></p>\r\n<p>I have also tried the following method, which does not prompt a zip download, but spits out the file as a jumbled character stream into the browser window:</p>\r\n<p><span style=\"color:#0000ff\">using (ZipFile zip = new ZipFile())<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zip.AddFile(Server.MapPath(_FileToBeZipped));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zip.Save(Response.OutputStream);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zip.Dispose();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.End();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p>\r\n<p>What is the new method for inserting a new zip file directly into the Output Stream?</p>",
    "PostedDate": "2009-07-07T10:43:59.84-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "209605",
    "ThreadId": "61753",
    "Html": "<p>Yep, the constructors that accept a Stream have been removed.</p>\r\n<p>The way to do it is to use the null (Default) constructor, and then ZipFile.Save(Stream).</p>\r\n<p>If you want to save to&nbsp;Response.OutputStream, then&nbsp;you want to Response.Clear() before beginning to write.&nbsp; Try something like this:</p>\r\n<pre>    Response.Clear();\r\n    Response.BufferOutput = false;\r\n    string archiveName= String.Format(&quot;archive-{0}.zip&quot;, DateTime.Now.ToString(&quot;yyyy-MMM-dd-HHmmss&quot;));\r\n    Response.ContentType = &quot;application/zip&quot;;\r\n    Response.AddHeader(&quot;content-disposition&quot;, &quot;filename=&quot; + archiveName);  \r\n    using (ZipFile zip = new ZipFile())\r\n    {\r\n        // filesToInclude is a IEnumerable (String[] or List etc)\r\n        zip.AddFiles(filesToInclude, &quot;files&quot;);\r\n        zip.Save(Response.OutputStream);\r\n    }\r\n    // Response.End();\r\n    HttpContext.Current.ApplicationInstance.CompleteRequest();\r\n\r\n</pre>\r\n<p>The reason you want BufferOutput = false is to prompt downloading immediately, even for large zip files. And the reason you should call Response.Clear() is to clear any prior headers that may have been set, indicating, for example, an incorrect content-type or cache header, which could result in a jumbled character stream in the browser window, when what you want is a &quot;Save As&quot; dialog.</p>\r\n<p>I think a best practice, when generating a ZIP From within ASP.NET, is to use an IHttpHandler (.ashx).&nbsp; That way you can avoid some overhead that would be incurred using an .aspx.</p>",
    "PostedDate": "2009-07-07T11:37:36.03-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "209618",
    "ThreadId": "61753",
    "Html": "<p>Thanks, Cheeso! This works great.</p>",
    "PostedDate": "2009-07-07T12:04:48.16-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]