[
  {
    "Id": "213513",
    "ThreadId": "62878",
    "Html": "<p>Basically, I have an openFileDialog box that allows the user to add a file...I want to name this file &quot;import.sql&quot;. But I also want to have the ability to update this zip with a new file and put the same name &quot;import.sql&quot; the second go around. I tried my code like this:</p>\r\n<p>zip.UpdateFile(openFileDialogInstall.FileName.ToString()).FileName=&quot;import.sql&quot;;</p>\r\n<p>And it seems to change the file as it adds it, but on updates, it adds another entry with the same name &quot;import.sql&quot; ...so in the same zip file, i have multiple import.sql files.</p>\r\n<p>How can I allow the user to choose a file, and add it to the zip file with a specific name, and later be able to update the import.sql file?</p>\r\n<p>Thanks</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-07-18T23:25:44.357-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "213549",
    "ThreadId": "62878",
    "Html": "<table border=0 width=720>\r\n<tbody>\r\n<tr>\r\n<td>\r\n<p>That's a bug.&nbsp;&nbsp; It should do what you want - replace the existing file by that name.&nbsp; I will fix the library.&nbsp; If you need a workaround in advance of the fix, you can do something like this:</p>\r\n<pre>     using (var zip = new ZipFile())\r\n     {\r\n         var e = zip.UpdateFile(SomeRandomFilename);\r\n         e.FileName= fixedFilename;\r\n         e.Comment = &quot;1st entry added&quot;;\r\n         /...\r\n         e = zip.UpdateFile(differentFileName);\r\n         if (zip.EntryFileNames.Contains(fixedFilename))\r\n             zip.RemoveEntry(fixedFilename);\r\n         e.FileName= fixedFilename;\r\n         e.Comment = &quot;2nd entry added&quot;;\r\n         zip.Save(&quot;Spinz.zip&quot;);\r\n     }\r\n</pre>\r\n</td>\r\n</tr>\r\n</tbody>\r\n</table>",
    "PostedDate": "2009-07-19T07:41:56.67-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "213552",
    "ThreadId": "62878",
    "Html": "This discussion has been copied to a work item. Click <a href=\"http://dotnetzip.codeplex.com/WorkItem/View.aspx?WorkItemId=8047\">here</a> to go to the work item and continue the discussion.",
    "PostedDate": "2009-07-19T07:47:10.06-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "213561",
    "ThreadId": "62878",
    "Html": "<p>ok, fixed.&nbsp; v1.8.4.7.</p>",
    "PostedDate": "2009-07-19T08:59:15.683-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "213563",
    "ThreadId": "62878",
    "Html": "<p>Thanks!</p>\r\n<p>So just to verify, the usages is like so: zip.UpdateFile(openFileDialogInstall.FileName.ToString()).FileName=&quot;import.sql&quot;;</p>\r\n<p>&nbsp;</p>\r\n<p>Also, wanted to verify, if I do this:</p>\r\n<p>zip.AddFile(openFileDialog.Filename.ToString());</p>\r\n<p>zip[openFileDialog.Filename.Tostring()].Filename=&quot;import.sql&quot;;</p>\r\n<p>I get an error that the instance name doesnt exist or something...is this by design?</p>",
    "PostedDate": "2009-07-19T09:21:17.3-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "213586",
    "ThreadId": "62878",
    "Html": "<p>yes, the first line of code is ok.</p>\r\n<p>And yes, the error you get is expected. The problem with the 2nd sequence of code is that typically filenames have a drive letter, and that is not allowed in a zip file.&nbsp;&nbsp;</p>\r\n<pre>  ZipEntry e = AddFile(ofd.Filename.ToString(); \r\n  // e.FileName != ofd.Filename.ToString() \r\n  // if ofd.Filename.ToString() == &quot;c:\\\\directory\\\\file.txt&quot;\r\n  // then e.Filename == /directory/file.text\r\n</pre>\r\n<p>The filename used to add the entry is transformed in 2 ways: the drive letter is removed and the backslashes get transformed into forward slashes.&nbsp;&nbsp;&nbsp;This is done to comply with the zipfile format.&nbsp; Backwards and forward slashes are treated as equal by the string indexer on the ZipFile class.&nbsp; So, when using the string indexer, you cannot use the drive letter, but it doesn't matter if you use forward slahes or backslashes. zip[&quot;\\\\directory\\\\file.txt&quot;]==zip[&quot;/directory/file.txt&quot;].</p>\r\n<p>Considering all this, I think the reason you get &quot;name doesn't exist&quot; (or whatever) is because of the drive letter. If you want to get the entry you just added, then why not do this:</p>\r\n<pre>  ZipEntry e = AddFile(ofd.Filename.ToString()); \r\n  e.FileName = &quot;import.sql&quot;; \r\n</pre>\r\n<p>rather than this:</p>\r\n<pre>  ZipEntry e = AddFile(ofd.Filename.ToString()); \r\n  zip[ofd.Filename.ToString()].FileName = &quot;import.sql&quot;; \r\n</pre>\r\n<p>The former seems clearer to me.</p>",
    "PostedDate": "2009-07-19T12:15:12.68-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]