[
  {
    "Id": "225135",
    "ThreadId": "66280",
    "Html": "<p>I am using the latest DotNetZipLib and am wondering when I zip to a disk file and use:&nbsp;&nbsp; <span style=\"font-size:x-small\">zip.AddFile(FileName, PathName);</span></p>\r\n<p><span style=\"font-size:x-small\">I get the correct modified time stamps of the files in the zip file.</span></p>\r\n<p><span style=\"font-size:x-small\">However when I zip to a memory stream and use:&nbsp; </span><span style=\"font-size:x-small\">zip.AddEntry(FileName, PathName, </span><span style=\"font-size:x-small;color:#2b91af\"><span style=\"font-size:x-small;color:#2b91af\">File</span></span><span style=\"font-size:x-small\">.ReadAllBytes(FileName));</span></p>\r\n<p><span style=\"font-size:x-small\">I do not get correct modified time stamps in the zip file&nbsp;but the timestamps are all the same.&nbsp; (I get the time of the zip operation).</span></p>\r\n<p>thanks</p>",
    "PostedDate": "2009-08-18T13:52:36.003-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "225146",
    "ThreadId": "66280",
    "Html": "<p>The behavior you are observing is expected.</p>\r\n<p>If you call ZipFile.AddFile(), you pass in the name of a file on the disk.&nbsp; The DotNetZip library can then open the file and retrieve its timestamps, and embed those timestamps into the zip archive, once it is saved.</p>\r\n<p>If you call ZipFile.AddEntry(), there is no way for DotNetZip to know where you got the content for the entry (in this case a byte array).&nbsp; You called File.ReadAllBytes(), but DotNetZip doesn't know that.&nbsp; To DotNetZip, it is just a byte array, and there is no way for DotNetZip to relate that byte array back to the source filesystem file.&nbsp; The bytes could just as easily have been randomly generated - there is no way for DotNetZip to know where you got them.&nbsp; Therefore there is no way for DotNetZip to intelligently set the timestamps on an entry added this way.</p>\r\n<p>You seem to be mixing up&nbsp;2 things:&nbsp; you said &quot;when I zip to a disk file&quot; and &quot;when I zip to a memory stream&quot;.&nbsp;&nbsp;&nbsp;&nbsp;I think when you say &quot;zip to a disk file&quot; you mean, savve the zip archive to a file in the filesystem.&nbsp; And when you say &quot;zip to a memory stream&quot; you mean &quot;save the zip archive to a&nbsp;MemoryStream.&quot;&nbsp;&nbsp;&nbsp;But&nbsp;the timestamps for the entries in a zipfile will not vary depending on&nbsp;how you save the ZipFile.&nbsp; The timestamps vary (as I described above) depending on how you add the entries.</p>\r\n<p>code example #1:</p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre><span style=\"color:Blue\">using</span> (<span style=\"color:Blue\">var</span> zip = <span style=\"color:Blue\">new</span> ZipFile())\r\n{\r\n    zip.AddFile(<span style=\"color:#A31515\">&quot;MyFile.txt&quot;</span>);\r\n    zip.Save(<span style=\"color:#A31515\">&quot;MyArchive.zip&quot;</span>);\r\n}\r\n</pre>\r\n</div>\r\n<p>The above code will save the zip archive into a filesystem file, and timestamps for the single entry will be intact.</p>\r\n<p>example 2:</p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre><span style=\"color:Blue\">using</span> (<span style=\"color:Blue\">var</span> ms = <span style=\"color:Blue\">new</span> MemoryStream())\r\n{\r\n  <span style=\"color:Blue\">using</span> (<span style=\"color:Blue\">var</span> zip = <span style=\"color:Blue\">new</span> ZipFile())\r\n  {\r\n      zip.AddFile(<span style=\"color:#A31515\">&quot;MyFile.txt&quot;</span>);\r\n      zip.Save(ms);\r\n  }\r\n}\r\n\r\n</pre>\r\n</div>\r\n<p>The above code will save the zip archive into a memory stream, and timestamps for the single entry will be intact.</p>\r\n<p>On the other hand, example 3:</p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre><span style=\"color:Blue\">using</span> (<span style=\"color:Blue\">var</span> zip = <span style=\"color:Blue\">new</span> ZipFile())\r\n{\r\n    zip.AddEntry(<span style=\"color:#A31515\">&quot;MyFile.txt&quot;</span>,<span style=\"color:#A31515\">&quot;&quot;</span>,File.ReadAllBytes(<span style=\"color:#A31515\">&quot;MyFile.txt&quot;</span>));\r\n    zip.Save(<span style=\"color:#A31515\">&quot;MyArchive.zip&quot;</span>);\r\n}\r\n</pre>\r\n</div>\r\n<p>The above code will save the zip archive into a filesystem file, but timestamps for the single entry will all show &quot;the current time&quot;.</p>\r\n<p>Likewise, example 4:</p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre><span style=\"color:Blue\">using</span> (<span style=\"color:Blue\">var</span> ms = <span style=\"color:Blue\">new</span> MemoryStream())\r\n{\r\n  <span style=\"color:Blue\">using</span> (<span style=\"color:Blue\">var</span> zip = <span style=\"color:Blue\">new</span> ZipFile())\r\n  {\r\n      zip.AddEntry(<span style=\"color:#A31515\">&quot;MyFile.txt&quot;</span>,<span style=\"color:#A31515\">&quot;&quot;</span>,File.ReadAllBytes(<span style=\"color:#A31515\">&quot;MyFile.txt&quot;</span>));\r\n      zip.Save(ms);\r\n  }\r\n}\r\n\r\n</pre>\r\n</div>\r\n<p>The above code will save the zip archive into a MemoryStream, but timestamps for the single entry will all show &quot;the current time&quot;.</p>",
    "PostedDate": "2009-08-18T14:24:02.43-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "225934",
    "ThreadId": "66280",
    "Html": "<p>Thanks for the clear explanation.&nbsp; Now I can zip in memory successfully with correct file timestamps and copy the files using a different set of credentials and then write to the zip file using default credentials!</p>",
    "PostedDate": "2009-08-20T09:15:58.473-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]