[
  {
    "Id": "230998",
    "ThreadId": "67948",
    "Html": "<p>\r\n<pre>Hello, <br><br>I'm having a problem adding file or folder to an archive. Here is the code I'm using:<div style=\"color:Black;background-color:White\"><pre>\r\n<span style=\"color:Blue\">public</span> <span style=\"color:Blue\">void</span> ZipDir(<span style=\"color:Blue\">string</span> fileName, <span style=\"color:Blue\">string</span> src, <span style=\"color:Blue\">string</span> dirInZip)\r\n{        \r\n    <span style=\"color:Blue\">using</span> (ZipFile zip = <span style=\"color:Blue\">new</span> ZipFile())\r\n    {\r\n        zip.SaveProgress += save_Progress;\r\n        zip.CompressionLevel = CompressionLevel.BestCompression;      \r\n        zip.AddSelectedFiles(selection, src, dirInZip, <span style=\"color:Blue\">true</span>);\r\n        zip.Save(fileName);\r\n    }\r\n} \r\n</pre>\r\n</div>\r\n<br><br>Works perfectly until I try adding a file or folder to the existing .zip file because instead of adding to the <br>archive it just overwrites it. I was under the impression that AddSelectedFiles will update and existing file. <br>Sorry if this is a redundant question but i couldn't find any discussions about it.<br><br>Thanks in advance <br></pre>\r\n</p>",
    "PostedDate": "2009-09-03T23:04:07.687-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "230999",
    "ThreadId": "67948",
    "Html": "<p>I'm sorry I don't understand the problem you're having.&nbsp;</p>\r\n<p>you wrote</p>\r\n<p>&gt; I was under the impression that AddSelectedFiles will update and existing file.</p>\r\n<p>&nbsp;</p>\r\n<p>and from your description, that is what's happening.</p>\r\n<p>?</p>\r\n<p>I don't see the problem.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-09-03T23:06:39.593-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "231110",
    "ThreadId": "67948",
    "Html": "<p>Ok lets say I want to add folder1 and folder2 to my archive, i will Write:</p>\r\n<p><span style=\"color:Blue\">&nbsp;</span>ZipDir( <span style=\"color:#000000\">File.zip</span>, Folder1, PathInArchive);</p>\r\n<p>then</p>\r\n<p>ZipDir( <span style=\"color:#000000\">File.zip</span>, Folder2, PathInArchive);</p>\r\n<p>&nbsp;</p>\r\n<p>but instead of the archive having Folder1 AND Folder2 it ends up with just folder 2 because it overwirtes the file instead of updating it.&nbsp;</p>",
    "PostedDate": "2009-09-04T05:33:35.587-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "231134",
    "ThreadId": "67948",
    "Html": "<table border=0 width=800>\r\n<tbody>\r\n<tr>\r\n<td>\r\n<p>Ah, ok.&nbsp; Well looking at your code</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> ZipDir(<span style=\"color:Blue\">string</span> fileName, <span style=\"color:Blue\">string</span> src, <span style=\"color:Blue\">string</span> dirInZip)\r\n{        \r\n    <span style=\"color:Blue\">using</span> (ZipFile zip = <span style=\"color:Blue\">new</span> ZipFile())\r\n    {\r\n        zip.SaveProgress += save_Progress;\r\n        zip.CompressionLevel = CompressionLevel.BestCompression;      \r\n        zip.AddSelectedFiles(selection, src, dirInZip, <span style=\"color:Blue\">true</span>);\r\n        zip.Save(fileName);\r\n    }\r\n} \r\n</pre>\r\n</div>\r\n<p>you create a zipfile instance, add files to it, and then save it to a zipfile.</p>\r\n<p>If you do that three times in a row, you will have written different data to the same filename 3 times. if you want to update an existing zip file, you will have to <em>open</em> the existing zip&nbsp;file before adding entries to it.</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> ZipDir(<span style=\"color:Blue\">string</span> fileName, <span style=\"color:Blue\">string</span> src, <span style=\"color:Blue\">string</span> dirInZip)\r\n{        \r\n    <span style=\"color:Blue\">using</span> (ZipFile zip = ZipFile.Read(fileName))\r\n    {\r\n        zip.SaveProgress += save_Progress;\r\n        zip.CompressionLevel = CompressionLevel.BestCompression;      \r\n        zip.AddSelectedFiles(selection, src, dirInZip, <span style=\"color:Blue\">true</span>);\r\n        zip.Save(fileName);\r\n    }\r\n} \r\n</pre>\r\n</div>\r\n</td>\r\n</tr>\r\n</tbody>\r\n</table>",
    "PostedDate": "2009-09-04T07:03:22.83-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "231143",
    "ThreadId": "67948",
    "Html": "<p>That works perfectly! thanks cheeso, you rock.</p>",
    "PostedDate": "2009-09-04T07:16:42.607-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "232435",
    "ThreadId": "67948",
    "Html": "<p>Ok one more small problem I'm having. Well i wouldn't say it's a problem but more of an inconvenience that I'd like to find a workaround for. Here is the method I use to add folders to a zip file:</p>\r\n<p>&nbsp;</p>\r\n<p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre>            SetExclusions();\r\n            <span style=\"color:Blue\">if</span> (File.Exists(fileName))\r\n            {\r\n                <span style=\"color:Blue\">using</span> (ZipFile zip = ZipFile.Read(fileName))\r\n                {\r\n                    zip.SaveProgress += save_Progress;                \r\n                    <span style=\"color:Blue\">if</span> (dir)\r\n                    {\r\n                    zip.AddSelectedFiles(exclude, src, dirInZip, <span style=\"color:Blue\">true</span>);\r\n                    }\r\n                    <span style=\"color:Blue\">else</span> \r\n                    {\r\n                        zip.AddFile(src);\r\n                    }\r\n                    zip.Save(fileName);\r\n                    zip.Dispose();                   \r\n                }\r\n            }\r\n            <span style=\"color:Blue\">else</span>\r\n            {\r\n                <span style=\"color:Blue\">using</span> (ZipFile zip = <span style=\"color:Blue\">new</span> ZipFile())\r\n                {\r\n                    zip.SaveProgress += save_Progress;\r\n                    <span style=\"color:Blue\">if</span> (dir)\r\n                    {\r\n                        zip.AddSelectedFiles(exclude, src, dirInZip, <span style=\"color:Blue\">true</span>);\r\n                    }\r\n                    <span style=\"color:Blue\">else</span>\r\n                    {\r\n                        zip.AddFile(src);\r\n                    }\r\n                    zip.Save(fileName);\r\n                    zip.Dispose();\r\n                }\r\n            }\r\n</pre>\r\n</div>\r\n</p>\r\n<p>&nbsp;</p>\r\n<p>This works perfectly except every time I add a new file or folder to the archive, it seems to &quot;re-add&quot; all the previous entries. Granted it &quot;re-adds&quot; them much faster than the first time but as you can imagine after the 5th or 6th entry this can take a good amount of time to complete. Is there any way I can avoid this? If not it's ok but it would greatly increase the performance of my program.</p>\r\n<p>Thanks.</p>",
    "PostedDate": "2009-09-08T16:22:01.167-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "232452",
    "ThreadId": "67948",
    "Html": "<p>I don't know what you mean by &quot;re-add all the previous entries.&quot;</p>\r\n<p>Can you tell me what the problem is, exactly?&nbsp;&nbsp; Is the zip file corrupted?&nbsp;&nbsp; Are you saying that it is just slow?</p>\r\n<p>Here's the thing, when saving a zip file, all the entries need to be written out.</p>\r\n<p>When updating a zipfile, all the entries are read in, and then when saving, all the entries will be written out.&nbsp; This includes any entries that originally came from the on-disk zipfile, as well as any new entries added with AddFile(), AddDirectory(), AddEntry() and so on.&nbsp;&nbsp; The entries that were in the original zipfile will just be streamed across - there's no compression performed because they are available in an already compressed. This is why it's faster the 2nd time through.&nbsp; But the IO still happens.</p>\r\n<p>There's no way to avoid writing out the entries.&nbsp; I think you may be concerned that the entries get&nbsp;written again, even if they&nbsp;were in the original zipfile.&nbsp; If you&nbsp;have a problem with IO speeds, don't save the ZipFile so often.&nbsp;</p>\r\n<p>By the way you can eliminate the big If statement by just using the ZipFile contructor that accepts a string.&nbsp;&nbsp; If the file exists it will read it.&nbsp; If the file does not exist it will create it.&nbsp; Check <a href=\"http://cheeso.members.winisp.net/DotNetZipHelp/html/ca1725fb-8fbc-c786-feb9-672fabd9140d.htm\">the doc</a> for more info.</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-09-08T18:00:17.01-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]