[
  {
    "Id": "470627",
    "ThreadId": "220522",
    "Html": "<p>Hello,</p>\r\n<p>Consider the following code snippet</p>\r\n<p>\r\n<div style=\"color:black;background-color:white\">\r\n<pre><span style=\"color:blue\">public</span> <span style=\"color:blue\">void</span> Process(Stream original, Stream modified)\r\n{\r\n    <span style=\"color:blue\">using</span> (<span style=\"color:blue\">var</span> zip = ZipFile.Read(original))\r\n    {\r\n        <span style=\"color:blue\">for</span> (<span style=\"color:blue\">var</span> index = 0; index &lt; _zip.Count; index++)\r\n        {\r\n            <span style=\"color:blue\">var</span> entry = _zip[index];\r\n            <span style=\"color:blue\">if</span> (entry.IsDirectory)\r\n            {\r\n                <span style=\"color:blue\">continue</span>;\r\n            }\r\n\r\n            <span style=\"color:blue\">const</span> FileOptions options = FileOptions.DeleteOnClose | FileOptions.Encrypted;\r\n            Stream stream = File.Create(Path.GetTempFileName(), 4096, options);\r\n            entry.Extract(stream);\r\n            <span style=\"color:green\">// process stream</span>\r\n            zip.UpdateEntry(entry.FileName, stream);\r\n        }\r\n        zip.Save(modified);\r\n    }\r\n}\r\n</pre>\r\n</div>\r\n</p>\r\n<p>UpdateEntry fails when a zip file has duplicate entries (like different document.doc and document.doc in the root). &nbsp;The message is &quot;System.ArgumentException: An item with the same key has already been added.&quot;.&nbsp;I can provide a test file created with 7zip, however, I don't see a way to attach it to this post.&nbsp;</p>\r\n<p>I only started looking at the source today and would appreciate any suggestions to fix this issue. &nbsp;In addition,&nbsp;I'd like to suggest that the entry itself has a Replace/SetContents method taking just a stream, path, or byte array. This will allow one to pass in a temporary file and still keep name of the ZipEntry the same. &nbsp;In fact, I don't care too much about the name of the entry, except that it must remain the same.</p>\r\n<p>Thanks,</p>\r\n<p>Werner</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-07-21T18:43:36.737-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]