[
  {
    "Id": "493449",
    "ThreadId": "227204",
    "Html": "<p>Hi,</p>\r\n<p>I have a small problem, which might me a stupid mistake on my side.</p>\r\n<p>Here is my code to create a zipfile when needed and the method to add a file to the archive.</p>\r\n<p>Adding a file works without problem but for some reason the Event is not fired after saving.</p>\r\n<p>I set a breakpoint at the zipFile_SaveProgress, the event is not fired.</p>\r\n<div style=\"color:black;background-color:white\">\r\n<pre>        <span style=\"color:blue\"><div style=\"color:black;background-color:white\"><pre><span style=\"color:blue\">class</span> CoverArchive\r\n    {\r\n        <span style=\"color:blue\">private</span> ZipFile zipFile;\r\n        <span style=\"color:blue\">private</span> String coverArchivePath;\r\n\r\n        <span style=\"color:blue\">public</span> CoverArchive()\r\n        {        \r\n            coverArchivePath = <span style=\"color:#a31515\">&quot;Archive\\\\Covers&quot;</span>;\r\n\r\n            <span style=\"color:blue\">if</span> (!File.Exists(<span style=\"color:#a31515\">&quot;Archive\\\\Covers&quot;</span>))\r\n            {\r\n                CreateZipFile();\r\n            }\r\n            <span style=\"color:blue\">using</span> (zipFile = ZipFile.Read(coverArchivePath))\r\n            {\r\n                <span style=\"color:green\">//zipFile.AddProgress += zipFile_AddProgress;</span>\r\n                <span style=\"color:green\">//zipFile.ExtractProgress += zipFile_ExtractProgress;</span>\r\n                <span style=\"color:green\">//zipFile.ZipError += zipFile_ZipError;</span>\r\n                zipFile.SaveProgress += zipFile_SaveProgress;\r\n            }\r\n        }\r\n\r\n        <span style=\"color:blue\">private</span> <span style=\"color:blue\">void</span> CreateZipFile()\r\n        {\r\n            zipFile = <span style=\"color:blue\">new</span> ZipFile();\r\n            zipFile.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;\r\n            zipFile.UseUnicodeAsNecessary = <span style=\"color:blue\">true</span>;\r\n            <span style=\"color:blue\">if</span> (!Directory.Exists(<span style=\"color:#a31515\">&quot;Archive&quot;</span>))\r\n                Directory.CreateDirectory(<span style=\"color:#a31515\">&quot;Archive&quot;</span>);\r\n            zipFile.Save(coverArchivePath);\r\n        }\r\n\r\n        <span style=\"color:blue\">public</span> <span style=\"color:blue\">void</span> AddCover(List&lt;String&gt; directories, String coverName, Stream fileStream)\r\n        {\r\n            <span style=\"color:blue\">try</span>\r\n            {\r\n                <span style=\"color:blue\">using</span> (zipFile = ZipFile.Read(coverArchivePath))\r\n                {\r\n                    String filePath = createPath(directories, coverName);\r\n                    ZipEntry entry = zipFile.AddEntry(filePath, fileStream);\r\n                    zipFile.Save();\r\n                }\r\n            }\r\n            <span style=\"color:blue\">catch</span> (Exception ex)\r\n            {\r\n                Console.WriteLine(<span style=\"color:#a31515\">&quot;Error adding File&quot;</span> + ex);\r\n            }\r\n        }\r\n        <span style=\"color:blue\">private</span> <span style=\"color:blue\">void</span> zipFile_SaveProgress(Object sender, SaveProgressEventArgs e)\r\n        {\r\n            <span style=\"color:blue\">if</span> (e.EventType == ZipProgressEventType.Saving_Completed)\r\n                Console.WriteLine(<span style=\"color:#a31515\">&quot;Save Done&quot;</span>);\r\n        }\r\n}\r\n</pre>\r\n</div>\r\n</span><br><br>Thank a lot in advance :)<br><br>EDIT:<br><br>Problem solved, I deleted the using statement and it worked :)<br>Admin can delete this entry ;)<br></pre>\r\n</div>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-09-14T11:33:23.387-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "495653",
    "ThreadId": "227204",
    "Html": "<p>The problem is with the using statement, but the solution is NOT to remove the using statement.&nbsp;</p>\r\n<p>The problem is you have called zipfile.Save(), which happens in your CreateZipFile() method, &nbsp;before attaching the progress event to the zipfile object, which happens later in the CoverArchive() method.&nbsp;</p>\r\n<p>I'd suggest refactoring your code to put the using() statement outside all references to the zipfile object. &nbsp;Do not remove the using() statement; that will result in other problems.&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-09-19T10:38:47.077-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]