[
  {
    "Id": "168642",
    "ThreadId": "50354",
    "Html": "Hello,<br>\r\n<br>\r\nI am using DotNetZip version 1.7.2.12 for .NET 2.0.  When I try to run the operation below, it throws an IOException (especially after the 2nd run).  I have tried several things including explicitly closing the file and calling GC collection.  This IOException only happens if I run the unzip function.  If I comment out the &quot;Using&quot; statement block, it runs successfully.  Is the unzip function somehow hanging onto the file?  Is my code correct?<br>\r\n<br>\r\nThanks in advance,<br>\r\n<br>\r\nError:<br>\r\n{&quot;The process cannot access the file 'D:\\\\test\\\\dest\\\\Temp_Backup\\\\source.zip' because it is being used by another process.&quot;}<br>\r\n<br>\r\nCode:<br>\r\n<br>\r\n<span style=\"font-size:13px\">\r\n<p>&nbsp;</p>\r\n</span>\r\n<p><span style=\"font-size:13px;color:#0000ff\">static</span><span style=\"font-size:13px\"> </span><span style=\"font-size:13px;color:#0000ff\">void</span><span style=\"font-size:13px\"> TestNewUnzipping()\r\n<p>&nbsp;</p>\r\n<p>{</p>\r\n<p>&nbsp;</p>\r\n</span></p>\r\n<p><span style=\"font-size:13px;color:#0000ff\">string</span><span style=\"font-size:13px\"> src = </span><span style=\"font-size:13px;color:#a31515\">@&quot;D:\\test\\source\\source.zip&quot;</span><span style=\"font-size:13px\">;\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n</span></p>\r\n<p><span style=\"font-size:13px;color:#0000ff\">string</span><span style=\"font-size:13px\"> dest = </span><span style=\"font-size:13px;color:#a31515\">@&quot;D:\\test\\dest\\Temp_Backup\\source.zip&quot;</span><span style=\"font-size:13px\">;\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n</span></p>\r\n<p><span style=\"font-size:13px;color:#0000ff\">string</span><span style=\"font-size:13px\"> outputFolder = </span><span style=\"font-size:13px;color:#a31515\">@&quot;D:\\test\\dest\\Temp_Backup\\&quot;</span><span style=\"font-size:13px\">;\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n</span></p>\r\n<p><span style=\"font-size:13px;color:#2b91af\">File</span><span style=\"font-size:13px\">.Copy(src, dest, </span><span style=\"font-size:13px;color:#0000ff\">true</span><span style=\"font-size:13px\">);\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n</span></p>\r\n<p><span style=\"font-size:13px;color:#0000ff\">using</span><span style=\"font-size:13px\"> (Ionic.Zip.</span><span style=\"font-size:13px;color:#2b91af\">ZipFile</span><span style=\"font-size:13px\"> zip = Ionic.Zip.</span><span style=\"font-size:13px;color:#2b91af\">ZipFile</span><span style=\"font-size:13px\">.Read(dest))\r\n<p>&nbsp;</p>\r\n<p>{</p>\r\n<p>&nbsp;</p>\r\n</span></p>\r\n<p><span style=\"font-size:13px;color:#0000ff\">foreach</span><span style=\"font-size:13px\"> (Ionic.Zip.</span><span style=\"font-size:13px;color:#2b91af\">ZipEntry</span><span style=\"font-size:13px\"> e </span><span style=\"font-size:13px;color:#0000ff\">in</span><span style=\"font-size:13px\"> zip)\r\n<p>&nbsp;</p>\r\n<p>{</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n</span></p>\r\n<p><span style=\"font-size:13px;color:#008000\">//e.Extract(outputFolder, true);\r\n<p>&nbsp;</p>\r\n</span></p>\r\n<span style=\"font-size:13px\">\r\n<p>e.ExtractWithPassword(outputFolder, </p>\r\n</span>\r\n<p><span style=\"font-size:13px;color:#0000ff\">true</span><span style=\"font-size:13px\">, </span><span style=\"font-size:13px;color:#a31515\">&quot;1234&quot;</span><span style=\"font-size:13px\">);\r\n<p>&nbsp;</p>\r\n<p>}</p>\r\n<p>&nbsp;</p>\r\n</span></p>\r\n<p><span style=\"font-size:13px;color:#008000\">//zip.Dispose();\r\n<p>&nbsp;</p>\r\n</span></p>\r\n<span style=\"font-size:13px\">\r\n<p>&nbsp;</p>\r\n</span>\r\n<p><span style=\"font-size:13px;color:#008000\">//GC.Collect();\r\n<p>&nbsp;</p>\r\n</span></p>\r\n<span style=\"font-size:13px\">\r\n<p>}</p>\r\n<p>&nbsp;</p>\r\n</span>\r\n<p><span style=\"font-size:13px;color:#2b91af\">File</span><span style=\"font-size:13px\">.Delete(dest);\r\n<p>&nbsp;</p>\r\n<p>}</p>\r\n</span></p>\r\n",
    "PostedDate": "2009-03-16T10:53:01.847-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "170485",
    "ThreadId": "50354",
    "Html": "<p>In theory what you are doing should work, but there are some possibilities for confusion or errors.<br>\r\nCan you post the stacktrace that you get with the exception?  You have said it is an exception, but you haven't said WHERE you get the exception.</p>\r\n<p>On the File.Delete() ? On the ZipFile.Read()?   on the File.Copy() ?  <br>\r\n<br>\r\nWhen you extract files, you appear to be extracting to the same directory that contains the zipfile you are reading. <br>\r\nIf there is contained within the zipfile, a file with the same name as the one you are reading, then you will likely get an exception. <br>\r\nIn other words if &quot;source.zip&quot; contains an entry by the name of &quot;source.zip&quot;, then the e.Extract() will try to overwrite a file that is in use. </p>\r\n<p>You should not have to explicitly call zip.Dispose() nor GC.Collect().  In fact, as a rule, NEVER EVER EVER call GC.Collect().   You likely don't need it.   The runtime is almost always smarter than you are about when it needs to do garbage collection! <br>\r\n<br>\r\nWhy are you copying the file anyway?  Why not just read it from the original location? <br>\r\nWhy copy the file, only to read and then delete it?  </p>\r\n",
    "PostedDate": "2009-03-21T22:53:45.727-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "179520",
    "ThreadId": "50354",
    "Html": "Same error here, the exception raises on File.Delete(). Im using the Compact Framework version on a PDA<br>\r\n<br>\r\n<br>\r\nZipFile zip = ZipFile.Read(pathFileZIP);<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (ZipEntry e in zip)<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nb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p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zip = null;<br>\r\nSystem.IO.File.delete(pathFileZIP); // IOException The process cannot access the file 'xxxx.zip' because it is being used by another process.<br>\r\n<br>\r\nI've tried too with using() and the same exception raises<br>\r\n",
    "PostedDate": "2009-04-15T04:15:13.33-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "179888",
    "ThreadId": "50354",
    "Html": "Though the exception here is the same as the original message, I don't think it's the same situation.  The first message had a zip file that contained a zip file of the same name.  It seemed that the extraction was extracting over the original zip file. OR at least there was a chance of that.  In any case, the code didn't make a ton of sense to me.  I never got a reply.  <br>\r\n<br>\r\nThe key thing for you is the use of the library on the CF.  There is no Dispose() on a Stream in .NET CF.  So, when you call ZipFile.Dispose(), it does not translate into a Dispose() on the corresponding stream that is used to read the zip file.  This is just the way the compact framework was designed.  It seems that the file pointer is not yet closed when you try to delete the file.  <br>\r\n<br>\r\nWhat I suggest is this: try a back-off interval.  Something like this: <br>\r\n<pre>bool retry = true;\r\nwhile (retry)\r\n{\r\n  try \r\n  {\r\n    System.IO.File.Delete(pathFileZIP);\r\n    retry = false;\r\n  }\r\n  catch (Exception e1)\r\n  {\r\n    retry = WantAnotherRetry();\r\n  }<br>  if (retry) Thread.Sleep(delayInterval); \r\n}\r\n</pre>\r\n<p>The criteria for continuing to retry could be, the number of attempts, or a time interval (you'd have to get the time before you start trying to delete, and then subtract it from the time of the current attempt), or something else. Up to you. </p>\r\n",
    "PostedDate": "2009-04-15T18:15:02.82-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "180008",
    "ThreadId": "50354",
    "Html": "well, I think too is not the same situation but...the title of the discussion is better fitting my issue i think.<br>\r\n<br>\r\nWith the back-off interval&nbsp; i finally can delete the file , but at the same time makes the library unusable, it takes at least 40 seconds to delete a 3k zip file. <br>\r\n<br>\r\nSo...<br>\r\nConnecting FTP ..less than 1 second<br>\r\ndownloading file ..less than 1 second<br>\r\nextracting files .. less than 0.5 seconds<br>\r\ndeleting file... 40-60 seconds....???<br>\r\n<br>\r\nI'm actually using another library to manage the unzip and i can delete the file inmediatly (but it has other issues xd) . So i think it must be an issue of DotNetzip.<br>\r\n<br>\r\nThanks in advance.<br>\r\n<br>\r\n<br>\r\n<br>\r\n<br>\r\n<br>\r\n",
    "PostedDate": "2009-04-16T01:33:59.987-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "463822",
    "ThreadId": "50354",
    "Html": "<p>I had the same problem as <a id=\"ctl00_ctl00_MasterContent_Content_PostRepeater_ctl08_UserNameLink\" href=\"http://www.codeplex.com/site/users/view/diesalher\">diesalher</a></p>\r\n<p>&nbsp;</p>\r\n<p>Now I use:</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; System::IO::FileStream^ fs = System::IO::File::OpenRead(fileName);<br><br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ZipFile^ zip = ZipFile::Read(fs);<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;for each (ZipEntry^ e in zip)<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;e-&gt;Extract(Folder, ExtractExistingFileAction::OverwriteSilently);<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;fs-&gt;Close();<br><br></p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-07-06T09:00:23.38-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]