[
  {
    "Id": "637672",
    "ThreadId": "263981",
    "Html": "\r\n<pre style=\"font-family:Consolas; font-size:13; color:black; background:white\"><span style=\"color:blue\">I'm keep getting Compressed (zipped) Folders Error. <br><strong>Windows Cannot open the folder. Access to the Compresses(zipped) folder 'C:\\x\\xx\\x123.zip' is denied.</strong><br><br>I can open the zip folder if I exit out the application.  How can I release the .zip file lock so that I don't have to exit out the application? </span><span style=\"color:blue\"><br>Any help!</span><br><span style=\"color:blue\"><br><br> using</span>&nbsp;(<span style=\"color:blue\">var</span>&nbsp;zipFile&nbsp;=&nbsp;<span style=\"color:blue\">new</span>&nbsp;<span style=\"color:#2b91af\">ZipFile</span>())\r\n {<br><pre style=\"font-family:Consolas; font-size:13px; color:black; background:none repeat scroll 0% 0% white\">zipFile.AddEntry(<span style=\"color:#2b91af\">Path</span>.Combine(zipPath,&nbsp;fileName),&nbsp;stream);\r\n</pre>\r\n<pre style=\"font-family:Consolas; font-size:13px; color:black; background:none repeat scroll 0% 0% white\">zipFile.Save(saveFileDialog.OpenFile());<br><br>}<br><br></pre>\r\n</pre>\r\n",
    "PostedDate": "2011-07-05T11:22:45.633-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "637710",
    "ThreadId": "263981",
    "Html": "<p>saveFileDialog.OpenFile() opens a stream.&nbsp;&nbsp;Apparently your app&nbsp;does not call .Close() on that stream, and this is why the file cannot&nbsp;be opened by Windows.&nbsp;&nbsp; If you modify your app to call .Close(), you'll be able to open the file externally, without exiting your app.&nbsp;</p>\n<p>You can (should) do it implicitly in a using clause. Something like this:</p>\n<div style=\"background-color: white; color: black;\">\n<pre>   SaveFileDialog saveFileDialog1 = <span style=\"color: blue;\">new</span> SaveFileDialog();\r\n   saveFileDialog1.Filter = <span style=\"color: #a31515;\">\"ZIP File|*.zip\"</span>;\r\n   saveFileDialog1.Title = <span style=\"color: #a31515;\">\"Save a ZIP File\"</span>;\r\n   saveFileDialog1.ShowDialog();\r\n\r\n   <span style=\"color: blue;\">if</span>(saveFileDialog1.FileName != <span style=\"color: #a31515;\">\"\"</span>)\r\n   {\r\n      <span style=\"color: blue;\">using</span> (<span style=\"color: blue;\">var</span> stream2 = saveFileDialog1.OpenFile())\r\n      {\r\n          <span style=\"color: blue;\">using</span> (<span style=\"color: blue;\">var</span> zip = <span style=\"color: blue;\">new</span> ZipFile()) \r\n          {\r\n             zip.AddEntry(Path.Combine(zipPath, fileName), stream1);\r\n             zip.Save(stream2);\r\n          }\r\n      }\r\n   }\r\n</pre>\n</div>\n<p>An alternative which may be simpler for you is to NOT open the filestream using OpenFile(), and instead just reference the filename itself in the call to ZipFile.Save(). like this:</p>\n<div style=\"background-color: white; color: black;\">\n<pre>   SaveFileDialog saveFileDialog1 = <span style=\"color: blue;\">new</span> SaveFileDialog();\r\n   saveFileDialog1.Filter = <span style=\"color: #a31515;\">\"ZIP file|*.zip\"</span>;\r\n   saveFileDialog1.Title = <span style=\"color: #a31515;\">\"Save a ZIP File\"</span>;\r\n   saveFileDialog1.ShowDialog();\r\n\r\n   <span style=\"color: blue;\">if</span>(saveFileDialog1.FileName != <span style=\"color: #a31515;\">\"\"</span>)\r\n   {\r\n          <span style=\"color: blue;\">using</span> (<span style=\"color: blue;\">var</span> zip = <span style=\"color: blue;\">new</span> ZipFile()) \r\n          {\r\n             zip.AddEntry(Path.Combine(zipPath, fileName), stream1);\r\n             zip.Save(saveFileDialog1.FileName);\r\n          }      \r\n   }\r\n\r\n\r\n</pre>\n</div>",
    "PostedDate": "2011-07-05T12:43:13.19-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "638227",
    "ThreadId": "263981",
    "Html": "<p>Cheeso,</p>\r\n<p>Thank you for your help. Your code snippet helped to fix the problem.</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2011-07-06T09:13:43.767-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]