[
  {
    "Id": "509821",
    "ThreadId": "231604",
    "Html": "<p>Everything is in the tittle, I think ;)</p>\r\n<p>Basically, when I use this code, I'm getting FileNotFoundException error at the last line.</p>\r\n<p>&nbsp;</p>\r\n<div style=\"color:black;background-color:white\">\r\n<pre>MemoryStream compressedStream = <span style=\"color:blue\">new</span> MemoryStream();<br><br>ZipFile zipFile = <span style=\"color:blue\">new</span> ZipFile();\r\n\r\nzipFile.AddFile( <span style=\"color:#a31515\">&quot;myFile.txt&quot;</span> );\r\nzipFile.Save( compressedStream );\r\n<br>// error myFile.zip doesn't exist<br>zipFile.Save( <span style=\"color:#a31515\">&quot;myFile.zip&quot;</span> );\r\n <br></pre>\r\n</div>\r\n<p>Maybe this problem is specified somewhere in the docs, but I didn't find it...</p>\r\n<p>Thanks</p>",
    "PostedDate": "2010-10-20T02:02:03.287-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "510121",
    "ThreadId": "231604",
    "Html": "<p>Hi Mmanatane,</p>\r\n<p>I've reproduced the problem here.</p>\r\n<p>Digging around in the code it looks like the first call to ZipFile.Save makes some changes to the internal state of the ZipFile object,&nbsp;and&nbsp;when you call Save again it tries to use this internal state to optimise the second save&nbsp;by avoiding recompressing files where it can. In this case it tries to read the pre-compressed bytes for each entry&nbsp;from&nbsp;a existing zip file, but&nbsp;the optimisation fails if the first Save was to a stream because it's trying to read from a file which doesn't exist at that point.</p>\r\n<p>In your case some options to work around this are:</p>\r\n<p>+ Move back to the start of your compressedStream and simply write the bytes out to the disk file yourself.</p>\r\n<p>+ Perform 2 rounds of compression - one to memory and one to disk - with a new ZipFile object each time.</p>\r\n<p>I'm sure Cheeso will have more insight into this, but the above will hopefully help in the meantime.</p>\r\n<p>Cheers,</p>\r\n<p>Mike</p>\r\n<p>P.S, for the record,&nbsp;the following fails as well:</p>\r\n<p>ZipFile zipFile = <span style=\"color:blue\">new</span> ZipFile();<br><br>zipFile.AddFile( <span style=\"color:#a31515\">&quot;myFile.txt&quot;</span> );<br>zipFile.Save( compressedStream );<br>// error - &quot;Object reference not set to an instance of an object.&quot;<br>zipFile.Save( compressedStream );</p>",
    "PostedDate": "2010-10-20T13:12:02.137-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]