[
  {
    "Id": "184711",
    "ThreadId": "54769",
    "Html": "Here's my problem, <br>\r\n<br>\r\nI created a static class (ZipUtil.cs) which has a bunch of methods which call DotNetLib and create an archive, update an archive, delete a file in the archive etc. <br>\r\nThe archive that is created when I call the static class throws the error &quot;Could not read signature - no data!&nbsp; (position 0x00005601)&quot; when I tried to add a file using the static class. <br>\r\nBut when I take the same code that is in the static class and put it directly in my main method (the commented stuff in Program.cs), the archive created works just fine when I try to add a file using the static class.<br>\r\n<br>\r\nHere are my two files. <br>\r\n<br>\r\n<p>Program.cs</p>\r\n<p>\r\n</p>\r\n<p><br>\r\nusing System;<br>\r\nusing Cps.Utility.CompressionUtils;<br>\r\nusing Ionic.Zip;<br>\r\n<br>\r\nnamespace Cps.Utility<br>\r\n{<br>\r\nclass Program<br>\r\n{<br>\r\nstatic void Main(string[] args)<br>\r\n{<br>\r\n//string dirname = @&quot;c:\\tmp\\dir1&quot;;<br>\r\n//string dir1 = &quot;dir1&quot;;<br>\r\n//using (ZipFile zip = new ZipFile(dirname + &quot;.zip&quot;))<br>\r\n//{<br>\r\n//    //zip.AddDirectory(@&quot;c:\\tmp\\dir1&quot;, &quot;dir1&quot;);<br>\r\n//    zip.AddDirectory(dirname, dir1);<br>\r\n//    zip.Save();<br>\r\n//}<br>\r\nif (&quot;create&quot;.Equals(args[0], StringComparison.CurrentCultureIgnoreCase))<br>\r\n{<br>\r\nConsole.WriteLine(&quot;Extracting Archive&quot;);<br>\r\nZipUtil.createArchive(@&quot;c:\\tmp\\dir1&quot;);<br>\r\nreturn;<br>\r\n}<br>\r\nif (&quot;extract&quot;.Equals(args[0], StringComparison.CurrentCultureIgnoreCase))<br>\r\n{<br>\r\nZipUtil.extractArchive(@&quot;c:\\tmp\\dir1.zip&quot;, @&quot;c:\\tmp\\dotnetzip\\&quot;);<br>\r\nreturn;<br>\r\n}<br>\r\nif (&quot;add&quot;.Equals(args[0], StringComparison.CurrentCultureIgnoreCase))<br>\r\n{<br>\r\nZipUtil.addFileToArchive(&quot;c:\\\\tmp\\\\crap.txt&quot;, &quot;dir1\\\\dir12&quot;, &quot;c:\\\\tmp\\\\dir1.zip&quot;);<br>\r\nreturn;<br>\r\n}<br>\r\nif (&quot;delete&quot;.Equals(args[0], StringComparison.CurrentCultureIgnoreCase))<br>\r\n{<br>\r\nZipUtil.removeFileFromArchive(@&quot;dir\\dir12\\crap.txt&quot;, @&quot;c:\\tmp\\dir1.zip&quot;);<br>\r\nreturn;<br>\r\n}<br>\r\nif (&quot;replace&quot;.Equals(args[0], StringComparison.CurrentCultureIgnoreCase))<br>\r\n{<br>\r\nZipUtil.updateFileInArchive(args[1], args[2], args[3]);<br>\r\nreturn;<br>\r\n}<br>\r\nif (&quot;move&quot;.Equals(args[0], StringComparison.CurrentCultureIgnoreCase))<br>\r\n{<br>\r\nZipUtil.moveFileInArchive(args[1], args[2], args[3], args[4]);<br>\r\nreturn;<br>\r\n}<br>\r\nthrow new NotImplementedException();<br>\r\n}<br>\r\n}<br>\r\n}<br>\r\n<br>\r\nZipUtil.cs<br>\r\n<br>\r\nusing System;<br>\r\nusing System.IO;<br>\r\nusing Ionic.Zip;<br>\r\n<br>\r\nnamespace Cps.Utility.CompressionUtils<br>\r\n{<br>\r\npublic class ZipUtil<br>\r\n{<br>\r\npublic static void createArchive(string directoryPath)<br>\r\n{<br>\r\nif (Directory.Exists(directoryPath) == false)<br>\r\nthrow new DirectoryNotFoundException();<br>\r\n<br>\r\nusing(ZipFile zip = new ZipFile(directoryPath+&quot;.zip&quot;))<br>\r\n{<br>\r\nzip.AddDirectory(directoryPath, (new DirectoryInfo(directoryPath)).Name);<br>\r\nzip.Comment = &quot;This zip was created at &quot; + DateTime.Now.ToString(&quot;G&quot;) ; <br>\r\nzip.Save();<br>\r\n}<br>\r\n}<br>\r\n<br>\r\npublic static void addFileToArchive(string filePath, string relativePathInArchive, string zipArchivePath)<br>\r\n{<br>\r\nif (File.Exists(zipArchivePath) == false)<br>\r\nthrow new FileNotFoundException(&quot;File Not Found&quot;, zipArchivePath);<br>\r\n//if (ZipFile.IsZipFile(zipArchivePath) == false)<br>\r\n//    throw new FileLoadException(&quot;Specified archive not a zip file&quot;);<br>\r\nif (File.Exists(filePath) == false)<br>\r\nthrow new FileNotFoundException(&quot;File Not Found&quot;, filePath);<br>\r\n<br>\r\nusing (ZipFile zip = ZipFile.Read(zipArchivePath))<br>\r\n{<br>\r\nzip.AddFile(filePath, relativePathInArchive);<br>\r\nzip.Comment = &quot;This zip archive was updated &quot; + DateTime.Now.ToString(&quot;G&quot;);<br>\r\nzip.Save(zipArchivePath);<br>\r\n}<br>\r\n}<br>\r\n<br>\r\npublic static void removeFileFromArchive(string relativePathInArchive, string zipArchivePath)<br>\r\n{<br>\r\nif (File.Exists(zipArchivePath) == false)<br>\r\nthrow new FileNotFoundException(&quot;File Not Found&quot;, zipArchivePath);<br>\r\nif (ZipFile.IsZipFile(zipArchivePath) == false)<br>\r\nthrow new FileLoadException(&quot;Specified archive not a zip file&quot;);<br>\r\n<br>\r\nusing (ZipFile zip = ZipFile.Read(zipArchivePath))<br>\r\n{<br>\r\nZipEntry e = zip[relativePathInArchive];<br>\r\n<br>\r\nif (e == null)<br>\r\nthrow new FileNotFoundException(&quot;File not found in archive&quot;, relativePathInArchive);<br>\r\n<br>\r\nzip.RemoveEntry(relativePathInArchive);<br>\r\nzip.Comment = &quot;This zip archive was updated &quot; + DateTime.Now.ToString(&quot;G&quot;);<br>\r\nzip.Save();<br>\r\n}<br>\r\n}<br>\r\n<br>\r\npublic static void updateFileInArchive(string filePath, string relativePathInArchive, string zipArchivePath)<br>\r\n{<br>\r\nif (File.Exists(zipArchivePath) == false)<br>\r\nthrow new FileNotFoundException(&quot;File Not Found&quot;, zipArchivePath);<br>\r\nif (ZipFile.IsZipFile(zipArchivePath) == false)<br>\r\nthrow new FileLoadException(&quot;Specified archive not a zip file&quot;);<br>\r\nif (File.Exists(filePath) == false)<br>\r\nthrow new FileNotFoundException(&quot;File Not Found&quot;, filePath);<br>\r\n<br>\r\nusing (ZipFile zip = ZipFile.Read(zipArchivePath))<br>\r\n{<br>\r\n// for this entry, update the archive  with content from the filesystem<br>\r\nZipEntry e = zip[relativePathInArchive];<br>\r\n<br>\r\nif (e == null)<br>\r\nthrow new FileNotFoundException(&quot;File not found in archive&quot;, relativePathInArchive);<br>\r\n<br>\r\nzip.UpdateItem(filePath);<br>\r\nzip.Comment = &quot;This zip archive was updated &quot; + DateTime.Now.ToString(&quot;G&quot;);<br>\r\nzip.Save();<br>\r\n}<br>\r\n}<br>\r\n<br>\r\npublic static void moveFileInArchive(string fileName, string filePathInArchive, string destFolderInArchive,<br>\r\nstring zipArchivePath)<br>\r\n{<br>\r\nif (File.Exists(zipArchivePath) == false)<br>\r\nthrow new FileNotFoundException(&quot;File Not Found&quot;, zipArchivePath);<br>\r\nif (ZipFile.IsZipFile(zipArchivePath) == false)<br>\r\nthrow new FileLoadException(&quot;Specified archive not a zip file&quot;);<br>\r\n<br>\r\nusing (ZipFile zip = ZipFile.Read(zipArchivePath))<br>\r\n{<br>\r\nZipEntry e = zip[filePathInArchive + fileName];<br>\r\n<br>\r\nif (e == null)<br>\r\nthrow new FileNotFoundException(&quot;File not found in archive&quot;, filePathInArchive);<br>\r\n<br>\r\ne.FileName = destFolderInArchive + filePathInArchive;<br>\r\nzip.Comment = &quot;This zip archive was updated &quot; + DateTime.Now.ToString(&quot;G&quot;);<br>\r\nzip.Save();<br>\r\n}<br>\r\n}<br>\r\n<br>\r\npublic static void extractArchive(string zipArchivePath, string destinationFolder)<br>\r\n{<br>\r\nif (File.Exists(zipArchivePath) == false)<br>\r\nthrow new FileNotFoundException(&quot;File Not Found&quot;, zipArchivePath);<br>\r\nif (ZipFile.IsZipFile(zipArchivePath) == false)<br>\r\nthrow new FileLoadException(&quot;Specified archive not a zip file&quot;);<br>\r\n<br>\r\nusing (ZipFile zip = ZipFile.Read(zipArchivePath))<br>\r\n{<br>\r\nforeach (ZipEntry e in zip)<br>\r\n{<br>\r\ne.Extract(destinationFolder, true); // overwrite == true<br>\r\n}<br>\r\n}<br>\r\n}<br>\r\n}<br>\r\n}<br>\r\n</pre>\r\n",
    "PostedDate": "2009-04-28T14:07:09.73-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "184714",
    "ThreadId": "54769",
    "Html": "It just doesn't make sense. <br>\r\n<br>\r\nIn scenario 1. <br>\r\n<br>\r\nI am creating a new ZipFile() inside a static method. <br>\r\n<br>\r\nIn the second case, I am calling new ZipFile() from the Main method which is also a static method. Why should the archive created in the first scenario be unrecognizable as a ZipFile (ZipFile.IsZipFile() returns false in scenario 1 but true in scenario 2)<br>\r\n<br>\r\n",
    "PostedDate": "2009-04-28T14:17:29.487-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "184735",
    "ThreadId": "54769",
    "Html": "I don't know what the problem might be, but I think you're on the right track. If the code works for you in one environment, you should be able to migrate it piecewise to the other environment. <br>\r\n<br>\r\n",
    "PostedDate": "2009-04-28T15:02:41.557-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "184957",
    "ThreadId": "54769",
    "Html": "Cheeso, <br>\r\n<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; It's all on one platform. I am using Windows vista and Visual Studio 2008. <br>\r\n<br>\r\nWhen I create the archive directly, there's no problem. <br>\r\n<br>\r\nWhen I put the creation of the archive into a static method in a utility class and call it, it creates a zip file that is unusable. I don't know how this is even possible. The code is included in the first entry. Please try it and see if you can reproduce the problem. <br>\r\n<br>\r\nAll you would need apart from the two files is the following. <br>\r\n<br>\r\ndirectories<br>\r\nc:\\tmp\\dir1<br>\r\nc:\\tmp\\dir1\\dir2<br>\r\n<br>\r\nfiles<br>\r\nc:\\tmp\\crap.txt<br>\r\n<br>\r\nThanks for your time!!<br>\r\n",
    "PostedDate": "2009-04-29T06:22:29.347-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "185109",
    "ThreadId": "54769",
    "Html": "Hey, I looked into this further and it looks like it may be a bug in DotNetZip to me. <br>\r\nI will have to look more deeply into it, but it appears to be related to the comment on the archive.<br>\r\nIf I remove the line that sets the comment on the archive as it is created, then the archive can later be read successfully. <br>\r\n<br>\r\nI will investigate further, and get back to you.<br>\r\n<br>\r\n<br>\r\n<br>\r\n<br>\r\n",
    "PostedDate": "2009-04-29T10:53:35.407-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "185121",
    "ThreadId": "54769",
    "Html": "The problem you saw is a bug in DotNetZip<br>\r\n<a href=\"http://dotnetzip.codeplex.com/WorkItem/View.aspx?WorkItemId=7711\">http://dotnetzip.codeplex.com/WorkItem/View.aspx?WorkItemId=7711</a><br>\r\n<br>\r\nTo workaround it, append 4 spaces to the comment text.  <br>\r\n<br>\r\n",
    "PostedDate": "2009-04-29T11:13:31.843-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "185148",
    "ThreadId": "54769",
    "Html": "Thanks Cheeso!!<br>\r\n<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; You are a life-saver. <br>\r\n",
    "PostedDate": "2009-04-29T12:03:29.4-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "185159",
    "ThreadId": "54769",
    "Html": "H- <br>\r\nglad to help. You may want to get v1.7.2.13 - an update for v1.7.  That will fix the problem and eliminate the need for the workaround.<br>\r\n",
    "PostedDate": "2009-04-29T12:18:41.597-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]