[
  {
    "Id": "409194",
    "ThreadId": "200425",
    "Html": "<p>Hello,</p>\r\n<p>I try to modify&nbsp; ZipEntry.FileName inside a Foreach loop but it's not working as the original Zip entry is modifying and the loop is broken</p>\r\n<p>here is my code (get from dotnetziplib sample):</p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre><span style=\"color:Blue\">foreach</span> (ZipEntry entry <span style=\"color:Blue\">in</span> zip)\r\n{\r\n     <span style=\"color:Blue\">if</span> (entry.FileName.EndsWith(<span style=\"color:#A31515\">&quot;.rtf&quot;</span>))\r\n     {\r\n          <span style=\"color:Blue\">var</span> newname = &quot;renamed_files\\\\&quot; + entry.FileName;\r\n\r\n          entry.FileName = newname;\r\n          entry.Comment = <span style=\"color:#A31515\">&quot;renamed&quot;</span>;                                                \r\n      }\r\n}      \r\n</pre>\r\n<pre>I get the following error:</pre>\r\n<pre>&quot;Collection was modified; enumeration operation may not execute.&quot;</pre>\r\n<pre>&nbsp;</pre>\r\n<pre>Do you have any idea How I can do that ?</pre>\r\n<pre>Thanks</pre>\r\n</div>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-02-26T09:07:25.907-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "409966",
    "ThreadId": "200425",
    "Html": "<p>Yes, try this.....</p>\r\n<p>foreach (ZipEntry entry in zip.EntriesSorted)</p>\r\n<p>I tried your code and got the same error.&nbsp; I think that it's unfortunate that the error occurs.&nbsp; I'll have to look into removing it.</p>",
    "PostedDate": "2010-02-26T11:12:46.843-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "409999",
    "ThreadId": "200425",
    "Html": "<p>The problem is that internally the set of entries is stored as a Dictionary&lt;String,ZipEntry&gt;.&nbsp; The string is the entry name.&nbsp; This allows quick access using the string indexer.&nbsp;</p>\r\n<p>Renaming an entry - setting the FileName on the entry -&nbsp; causes the entry to be removed and then re-added into the Dictionary. This modifies the collection and prevents the foreach from continuing.</p>\r\n<p>You have the workaround I have to you.&nbsp; Another possible workaround is to copy the list of entries and enumerate through the copy.</p>\r\n<p>A&nbsp;possible solution is for DotNetZip to return a copy of the List for the foreach loop.&nbsp; With the fix you could do &quot;foreach(var entry in zip) ...&quot; and get the expected results, even if you rename an entry within the loop.&nbsp; The problem is that for large zip files, doing a copy for a foreach loop that does not involve renaming any entries, would be unnecessarily slow, and memory hungry.&nbsp; So at this point I'm not sure I want to make the change.</p>\r\n<p>For now I am leaning toward making a document change that describes this limitation and the workarounds.</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-02-26T11:17:53.27-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "410153",
    "ThreadId": "200425",
    "Html": "This discussion has been copied to a work item. Click <a href=\"http://dotnetzip.codeplex.com/WorkItem/View.aspx?WorkItemId=10331\">here</a> to go to the work item and continue the discussion.",
    "PostedDate": "2010-02-26T11:41:40.66-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]