[
  {
    "Id": "226933",
    "ThreadId": "66761",
    "Html": "<p>I must be missing something simple.</p>\r\n<p>I had a problem saving memory streams to a zip file. When the file saved to disk or written to an ASP.Net response stream, the files would all have zero lengths.</p>\r\n<p>With this code, all the filenames are present, but the files are zero length:</p>\r\n<p>&nbsp;</p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre><span style=\"color:Blue\">using</span> (ZipFile zip = <span style=\"color:Blue\">new</span> ZipFile())\r\n{\r\n    <span style=\"color:Blue\">foreach</span> (<span style=\"color:Blue\">var</span> image <span style=\"color:Blue\">in</span> list)\r\n    {\r\n        <span style=\"color:Blue\">var</span> stream = GetStream(image);\r\n        <span style=\"color:Blue\">var</span> entry = zip.AddEntry(image.ImageName, <span style=\"color:#A31515\">&quot;&quot;</span>, stream);\r\n    }\r\n\r\n    context.Response.ContentType = <span style=\"color:#A31515\">&quot;application/zip&quot;</span>;\r\n    zip.Save(context.Response.OutputStream);\r\n\r\n    HttpContext.Current.ApplicationInstance.CompleteRequest();\r\n}\r\n</pre>\r\n</div>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<p>This worked well:</p>\r\n<p>&nbsp;</p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre><span style=\"color:Blue\">using</span> (ZipFile zip = <span style=\"color:Blue\">new</span> ZipFile())\r\n{\r\n    <span style=\"color:Blue\">foreach</span> (<span style=\"color:Blue\">var</span> image <span style=\"color:Blue\">in</span> list)\r\n    {\r\n        <span style=\"color:Blue\">var</span> stream = GetStream(image);\r\n        <span style=\"color:Blue\">byte</span>[] bytes = stream.ToArray();\r\n        <span style=\"color:Blue\">var</span> entry = zip.AddEntry(image.ImageName, <span style=\"color:#A31515\">&quot;&quot;</span>, bytes);\r\n    }\r\n\r\n    context.Response.ContentType = <span style=\"color:#A31515\">&quot;application/zip&quot;</span>;\r\n    zip.Save(context.Response.OutputStream);\r\n\r\n    HttpContext.Current.ApplicationInstance.CompleteRequest();\r\n}\r\n</pre>\r\n</div>\r\n<p>FYI, the images are cached as MemoryStreams and accessed with a special object. If I did a stream.WriteTo(context.Repsonse.OutputStream) and set the appropriate contentType, the image displayed fine in the browser.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-08-24T00:04:17.183-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "226957",
    "ThreadId": "66761",
    "Html": "<p>Can you check the Position on each stream before adding it?&nbsp;&nbsp; Or, try a stream.Seek(0, SeekOrigin.Begin).&nbsp;&nbsp;&nbsp; If the stream cursor is at the end of the stream, you will have this problem.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-08-24T02:00:25.623-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "227304",
    "ThreadId": "66761",
    "Html": "<p>Ahhhh. I actually had that thought because I saw the position in the debugger. I tried just setting the stream.position to zero, but that didn't work. That's what I get for coding at 2am. ;-)</p>\r\n<p>Awesome library! Thanks.</p>\r\n<p>I was dreading doing my latest project with SharpZipLib. This was soooo much easier.</p>\r\n<p>Thanks again.</p>",
    "PostedDate": "2009-08-24T20:17:21.247-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "227312",
    "ThreadId": "66761",
    "Html": "<p>Thanks for the good words. Yeah, I agree with you on SharpZipLib. I put this library together because I didn't like it.&nbsp; It was too complicated to use.&nbsp;&nbsp; And then DotNetZip just kept getting bigger and bigger...</p>",
    "PostedDate": "2009-08-24T20:42:42.083-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "263909",
    "ThreadId": "66761",
    "Html": "<p>also, I think you should use Response.Close() instead of HttpContext.Current.ApplicationInstance.CompleteRequest();</p>",
    "PostedDate": "2009-12-05T05:02:56.2-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]