[
  {
    "Id": "657232",
    "ThreadId": "268878",
    "Html": "\r\n<p>Hi,</p>\r\n<p>I am using latest build and using the Zip Class.</p>\r\n<p>I did not test this further yet, but I will:</p>\r\n<p>When i'm unzipping a file and the folder already contains a file called</p>\r\n<p>filename.tmp</p>\r\n<p>the unzip just fails with an error, that the file already exists.</p>\r\n<p>(for example: i extract the test.txt to the folder TestFolder and in that folder there is a file called test.txt.tmp)</p>\r\n<p>So would it be good to check the folder, to where I extract files, for .tmp files and delete them?</p>\r\n<p>Or is there any other way?</p>\r\n<p>Another Question would be: from what i understand of that, i could never zip a filename.tmp or unzip it right?</p>\r\n<p>Thanks for your help.</p>\r\n",
    "PostedDate": "2011-08-12T09:26:54.063-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "657887",
    "ThreadId": "268878",
    "Html": "<p>I think your characterization of the situation is not quite right.&nbsp;</p>\n<p><em>When i'm unzipping a file and the folder already contains a file called \"filename.tmp\" the unzip just fails with an error, that the file already exists.</em></p>\n<p>The way you've&nbsp;described the situation, it is specific to a particular filename.&nbsp; This is untrue, I think.&nbsp;&nbsp;On the other hand, the ZipFile class will not overwrite existing files during extraction, unless you specifically ask it to.&nbsp; there is&nbsp;a property called ExtractExistingFileAction, which tells the class what to do when extraction would overwrite an existing file.</p>\n<p>&nbsp;&gt;&nbsp;&nbsp;i could never zip a filename.tmp or unzip it right?</p>\n<p>I don't think that is correct.&nbsp; If you have a test case that exhibits this behavior, please post the code.</p>\n<p>&nbsp;</p>",
    "PostedDate": "2011-08-13T17:57:50.693-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "658421",
    "ThreadId": "268878",
    "Html": "<p>Ok let me try to explain it better.</p>\n<p>I zip the folder C:\\Test\\ which contains:<br /> helloworld.txt<br /> test.txt</p>\n<p>now i zip it with the following code (real code is more complicated, but to get you an idea of what I use):</p>\n<div style=\"color: black; background-color: white;\">\n<pre><span style=\"color: blue;\">using</span> (ZipFile zip = <span style=\"color: blue;\">new</span> ZipFile())\n{\n  zip.CompressionLevel = Ionic.Zlib.CompressionLevel.Level5\n  <span style=\"color: green;\">//zip.ProvisionalAlternateEncoding = Encoding.UTF8;</span>\n  zip.AlternateEncoding = Encoding.UTF8;\n  zip.AlternateEncodingUsage = ZipOption.AsNecessary;\n  zip.UseZip64WhenSaving = Zip64Option.AsNecessary;\n  zip.AddItem(<span style=\"color: #a31515;\">\"C:\\Test\\\",\"</span>\");\n  zip.Save(<span style=\"color: #a31515;\">\"C:\\Test.zip\"</span>);\n}\n</pre>\n</div>\n<p>Unzip the zipfile with the following code:</p>\n<div style=\"color: black; background-color: white;\">\n<pre>ZipFile zip = ZipFile.Read(<span style=\"color: #a31515;\">\"C:\\Test.zip\"</span>);\n<span style=\"color: blue;\">foreach</span> (ZipEntry ze <span style=\"color: blue;\">in</span> zip)\n{\n        ze.ExtractExistingFile = ExtractExistingFileAction.OverwriteSilently;\n        ze.Extract(\"C:\\Test\\\");\n}\n</pre>\n</div>\n<p>&nbsp;</p>\n<p>What happens now is, for each file in the zipfile the library creates a filename.ext.tmp while he unpacks the specific file of the ze.Extract.<br /> That means, when it extracts helloworld.txt on ze.Extract(...); in the folder c:\\test\\ there will be a file called helloworld.txt.tmp till extract finishes (use big files to test).</p>\n<p>I think that this is no problem at all, but, when C:\\test already has a file called helloworld.txt.tmp and i try to extract helloworld.txt in that folder, the library just fails with the message, that the file already exists (the helloworld.txt.tmp, not  the helloworld.txt).</p>\n<p>&nbsp;</p>\n<p>Normaly this never happens, but when i unpack a zipfile to a folder and a file in that zipfile fails to extract (for example crc check fails), then the library creates the .tmp file while extracting, fails to extract  with an error (crc check) and leaves the .tmp there. When I extract again now, the library tells me that the .tmp file already exists and fails again.</p>\n<p>&nbsp;</p>\n<p>The ExtractExistingFileAction.OverwriteSilently does not apply for that .tmp files and the zip.TempFileFolder is just used for zip.save() but not for extraction (i tried to do a workaround with a tmp folder which i always clear before extracting something).</p>\n<p>So far... I'm still working on this. I think I need to clear all .tmp files of the folders to which I will extract stuff (Wanted to avoid that solution, since I dont know if that folder does not need those .tmp files for something else).</p>",
    "PostedDate": "2011-08-15T10:56:35.843-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "658512",
    "ThreadId": "268878",
    "Html": "<p>yes, I see now.</p>\r\n<p>A very clear&nbsp;explanation.&nbsp; I see that you are correct, and this is a problem.&nbsp;Actually 2 problems:</p>\r\n<ol>\r\n<li>The temporary filename used by dotnetzip could clash with an existing file in the folder. </li>\r\n<li>the temporary file remains after a failed extraction</li>\r\n</ol>\r\n<p>I can correct the first problem.&nbsp;</p>\r\n<p>But the second problem - can you provide some code that causes this scenario?&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2011-08-15T13:29:08.847-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "658517",
    "ThreadId": "268878",
    "Html": "This discussion has been copied to a work item. Click <a href=\"http://dotnetzip.codeplex.com/workitem/14097\">here</a> to go to the work item and continue the discussion.",
    "PostedDate": "2011-08-15T13:31:40.08-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "658640",
    "ThreadId": "268878",
    "Html": "<p>For the second problem, what you need is an faulty/broken zip, which is ok to read, but fails to extract one or more files (one is enough). I can not produce a zip file like that at the moment (no idea how) and i can't send you the one i actually have, cause it's a sensitive file of a customer.</p>\r\n<p>The easiest broken file would be a zip file which has a wrong CRC code for one of the files it contains. I'll try to produce a zip file like that later if I can (or something similar).</p>",
    "PostedDate": "2011-08-15T19:10:16.207-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "658698",
    "ThreadId": "268878",
    "Html": "<p>The code sample in this work item produces a zip with an invalid CRC:</p>\r\n<p><a href=\"http://dotnetzip.codeplex.com/workitem/14087\">http://dotnetzip.codeplex.com/workitem/14087</a></p>\r\n<p>Might help reproduce the *.tmp file&nbsp;issue above.</p>",
    "PostedDate": "2011-08-16T00:15:39.457-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "658782",
    "ThreadId": "268878",
    "Html": "<p>Thanks for you code sample pointy.</p>\n<p>I got through this now... this was more complicated then i thought, cause the filename.ext.tmp file only exists after extraction fails when the filename.ext exists prior to extraction.</p>\n<p>Here is a working code sample to fully reproduce the problem (delete content of C:\\test\\ before you start it):</p>\n<p>&nbsp;</p>\n<div style=\"color: black; background-color: white;\">\n<pre>      String faultstring = <span style=\"color: blue;\">new</span> String(<span style=\"color: #a31515;\">' '</span>, 2490368);\n      <span style=\"color: blue;\">string</span> okstring = <span style=\"color: #a31515;\">\"Hello World!\"</span>;\n\n      <span style=\"color: blue;\">try</span>\n      {\n        System.IO.Directory.CreateDirectory(<span style=\"color: #a31515;\">\"C:\\\\Test\"</span>);\n        System.IO.Directory.CreateDirectory(<span style=\"color: #a31515;\">\"C:\\\\Test\\\\Test\"</span>);\n\n        System.IO.File.WriteAllText(<span style=\"color: #a31515;\">\"C:\\\\Test\\\\test.txt\"</span>, faultstring);\n        System.IO.File.WriteAllText(<span style=\"color: #a31515;\">\"C:\\\\Test\\\\hello.txt\"</span>, okstring);\n        <span style=\"color: green;\">// comment the next two lines out to have no test.txt.tmp:</span>\n        System.IO.File.Copy(<span style=\"color: #a31515;\">\"C:\\\\Test\\\\test.txt\"</span>, <span style=\"color: #a31515;\">\"C:\\\\Test\\\\Test\\\\test.txt\"</span>, <span style=\"color: blue;\">true</span>);\n        System.IO.File.Copy(<span style=\"color: #a31515;\">\"C:\\\\Test\\\\hello.txt\"</span>, <span style=\"color: #a31515;\">\"C:\\\\Test\\\\Test\\\\hello.txt\"</span>, <span style=\"color: blue;\">true</span>);\n        MessageBox.Show(<span style=\"color: #a31515;\">\"files created...\"</span>);\n      }\n      <span style=\"color: blue;\">catch</span> (Exception ex)\n      {\n        MessageBox.Show(ex.Message);\n      }\n\n      <span style=\"color: blue;\">try</span>\n      {\n        <span style=\"color: blue;\">using</span> (ZipFile zip = <span style=\"color: blue;\">new</span> ZipFile())\n        {\n          zip.CompressionLevel = Ionic.Zlib.CompressionLevel.Level5;\n          zip.AlternateEncoding = Encoding.UTF8;\n          zip.AlternateEncodingUsage = ZipOption.AsNecessary;\n          zip.UseZip64WhenSaving = Zip64Option.AsNecessary;\n\n          zip.AddFile(<span style=\"color: #a31515;\">\"C:\\\\Test\\\\hello.txt\"</span>, <span style=\"color: #a31515;\">\"\"</span>);\n          zip.AddFile(<span style=\"color: #a31515;\">\"C:\\\\Test\\\\test.txt\"</span>, <span style=\"color: #a31515;\">\"\"</span>);\n          zip.Save(<span style=\"color: #a31515;\">\"C:\\\\Test\\\\test.zip\"</span>);\n          MessageBox.Show(<span style=\"color: #a31515;\">\"zip created...\"</span>);\n        }\n      }\n      <span style=\"color: blue;\">catch</span> (Exception ex)\n      {\n        MessageBox.Show(ex.Message);\n      }\n\n      <span style=\"color: blue;\">try</span>\n      {\n        <span style=\"color: blue;\">using</span> (ZipFile zip = ZipFile.Read(<span style=\"color: #a31515;\">\"C:\\\\Test\\\\test.zip\"</span>))\n        {\n          <span style=\"color: blue;\">foreach</span> (ZipEntry ze <span style=\"color: blue;\">in</span> zip)\n          {\n            ze.ExtractExistingFile = ExtractExistingFileAction.OverwriteSilently;\n            ze.Extract(<span style=\"color: #a31515;\">\"C:\\\\Test\\\\Test\"</span>);\n          }\n        }\n        MessageBox.Show(<span style=\"color: #a31515;\">\"zip extracted...\"</span>);\n      }\n      <span style=\"color: blue;\">catch</span> (Exception ex)\n      {\n        MessageBox.Show(ex.Message);\n      }\n<br /><br /></pre>\n</div>\n<p>If you don't out comment the two lines in the code (mentioned), then u will now have a file C:\\Test\\Test\\test.txt.tmp</p>\n<p>Regards,<br />DexMiK</p>",
    "PostedDate": "2011-08-16T04:48:30.643-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "893824",
    "ThreadId": "268878",
    "Html": "<p>Hello,</p>\r\n<p>I'm also running into this behavior. Are there any plans to update the code for this any time soon? Why not just create a .tmp file in a temp directory...?</p>",
    "PostedDate": "2012-07-31T11:09:52.4-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "1022201",
    "ThreadId": "268878",
    "Html": "Same problem here. March, 2013.<br />\n<br />\nThe only workaround right now is to recursively delete *.tmp before unzipping.<br />\n<pre><code>myOutputDirectory.GetFiles(&quot;*.tmp&quot;, SearchOption.AllDirectories).ToList().ForEach(file=&gt;file.Delete());</code></pre>\n\nLéon Pelletier<br />\n",
    "PostedDate": "2013-03-27T20:50:41.497-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "1074945",
    "ThreadId": "268878",
    "Html": "I have the same problem, in the latest version (currently 1.9.1.8 ~2011)<br />\n<br />\nWhat could be the reason for saving temp files <em>not</em> into the system temp directory by default? <br />\n<br />\nLooks like we can do this by doing:<br />\n<pre><code>using (var zip = new ZipFile(zipfileName)) { zip.TempFileFolder = Path.GetTempPath();...</code></pre>\n\n",
    "PostedDate": "2013-07-30T22:23:41.263-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]