[
  {
    "Id": "418276",
    "ThreadId": "205006",
    "Html": "<p>I hope someone can help me with the following issue:</p>\r\n<p>When I try to&nbsp;download a zip folder to my Mac hard drive through Safari, the automatic decompression does not work. Also, the foldername gets to be extended - for example if the folder name is &quot;abc.zip&quot; it becomes &quot;abc.zip, filename=abc.zip&quot;</p>\r\n<p>This happens only on Mac, using Safari. All works very well on pc platforms and other browsers. Does anyone know of any known issue or a solution to this?</p>\r\n<p>thanks</p>",
    "PostedDate": "2010-03-15T08:33:10.437-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "418334",
    "ThreadId": "205006",
    "Html": "<p>show me the code you use to generate and download the ZIP file.</p>",
    "PostedDate": "2010-03-15T10:38:44.523-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "418342",
    "ThreadId": "205006",
    "Html": "<p>Hi Cheeso, thanks a lot&nbsp;for taking a look at this. here is the code:</p>\r\n<p>Private Sub ZipFolder(ByVal FolderToZip As String)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Clear()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.BufferOutput = False</p>\r\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim archiveName As String = _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Path.GetFileName(FolderToZip) &amp; &quot;_&quot; &amp; (DateTime.Now.ToString(&quot;yyyyMMMdd_HHmmss&quot;)) &amp; &quot;.zip&quot;</p>\r\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.ContentType = &quot;application/zip&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.AddHeader(&quot;content-disposition&quot;, &quot;filename=&quot; + archiveName)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.AddHeader(&quot;content-disposition&quot;, &quot;filename=&quot; + archiveName)</p>\r\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Using zip As ZipFile = New ZipFile()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zip.AddDirectory(FolderToZip)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zip.Save(Response.OutputStream)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zip.Dispose()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' Send the output to the client.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Flush()</p>\r\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Using<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpContext.Current.ApplicationInstance.CompleteRequest()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' Response.Close()</p>\r\n<p>&nbsp;&nbsp;&nbsp; End Sub</p>",
    "PostedDate": "2010-03-15T10:51:06.383-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "418343",
    "ThreadId": "205006",
    "Html": "<p>I just want to emphasize that this works with all browsers on pc - it is only on mac and safari that i have this problem.</p>\r\n<p>thanks again.</p>",
    "PostedDate": "2010-03-15T10:53:15.05-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "418358",
    "ThreadId": "205006",
    "Html": "<p>I fixed the file name issue myslef - it was a duplicate of two lines in my code. However, the decompression is still an issue.</p>",
    "PostedDate": "2010-03-15T11:25:14.173-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "418360",
    "ThreadId": "205006",
    "Html": "<p>You should make some changes in your code:</p>\r\n<ol>\r\n<li>Definitely use <strong>Response.Close </strong>insteead of <strong>ApplicationInstance.CompleteRequest()</strong>.&nbsp; </li>\r\n<li>do you really have two of these lines?&nbsp; <strong>Response.AddHeader(&quot;content-disposition&quot;, &quot;filename=&quot;&nbsp;+ archiveName)&nbsp; <br></strong>if so, remove one. </li>\r\n<li>Change the remaining call to Response.AddHeader to be:<br>&nbsp; <strong>Response.AddHeader(&quot;Content-Disposition&quot;, &quot;<span style=\"color:#ff0000\">inline;</span> filename=&quot;&nbsp;<span style=\"color:#ff0000\">&amp; chr(34) &amp; </span>archiveName <span style=\"color:#ff0000\">&amp; chr(34)</span>)</strong></li>\r\n<li>Remove the call to <strong>Response.Flush </strong>and <strong>zip.Dispose </strong>. They are both unnecessary. </li>\r\n</ol>\r\n<p>All these changes should be made in any case; the code is not correct as you have it now.&nbsp;</p>\r\n<p>The modified code you should have, after those changes, looks like this:</p>\r\n<div style=\"border:solid .1em #ccc;color:Black;background-color:White;margin:.25em 1em 0 1em;padding:0.25em .25em 0.25em .25em\">\r\n<pre><span style=\"color:Blue\">Private</span> <span style=\"color:Blue\">Sub</span> ZipFolder(<span style=\"color:Blue\">ByVal</span> FolderToZip <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">String</span>)\r\n    Response.Clear()\r\n    Response.BufferOutput = <span style=\"color:Blue\">False</span>\r\n\r\n    <span style=\"color:Blue\">Dim</span> archiveName <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">String</span> = _\r\n        Path.GetFileName(FolderToZip) &amp; <span style=\"color:#A31515\">&quot;_&quot;</span> &amp; (DateTime.Now.ToString(<span style=\"color:#A31515\">&quot;yyyyMMMdd_HHmmss&quot;</span>)) &amp; <span style=\"color:#A31515\">&quot;.zip&quot;</span>\r\n\r\n    Response.ContentType = <span style=\"color:#A31515\">&quot;application/zip&quot;</span>\r\n    Response.AddHeader(<span style=\"color:#A31515\">&quot;Content-Disposition&quot;</span>, <span style=\"color:#A31515\">&quot;filename=&quot;</span> &amp; chr(34) &amp; archiveName &amp; chr(34))\r\n\r\n    <span style=\"color:Blue\">Using</span> zip <span style=\"color:Blue\">As</span> ZipFile = <span style=\"color:Blue\">New</span> ZipFile()\r\n        zip.AddDirectory(FolderToZip)\r\n        zip.Save(Response.OutputStream)\r\n    <span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Using</span>\r\n    Response.Close()\r\n<span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Sub</span>\r\n\r\n</pre>\r\n</div>\r\n<p>This should fix your problem.</p>\r\n<p>Now, some further explanation, in case you are interested:</p>\r\n<p>There was? is?&nbsp; a known behavior in Safari - it ignores the filename parameter in the Content-Disposition header.&nbsp; It has been called &quot;a problem&quot; or &quot;a bug&quot; but I hesitate to label it that way, because the Content-Disposition header (see IETF RFC 2183) is not formally part of the HTTP standard, and so Safari is not incorrect in behaving differently, if you get my meaning.&nbsp; Most other browsers implement Content-Disposition, but there are some issues with it, and it's truly a fuzzy area of the HTTP protocol.&nbsp; And this is why you are seeing the difference in behaivor. It has nothing to do with DotNetZip.&nbsp; It's just a difference in the way Safari handles the header.&nbsp;</p>\r\n<p>If the problem still is not solved, even after the above changes, then I don't know what you can do.&nbsp;</p>\r\n<p>As I said, this is not a DotNetZip issue; it's a Safari/HTTP thing.&nbsp; So you may want to try a support forum for Mac developers or web developers&nbsp;for more hints.&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-03-15T11:36:05.687-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "418375",
    "ThreadId": "205006",
    "Html": "<p>Thanks. I know what you mean with the HTTP standard.</p>\r\n<p>I changed my code,&nbsp; the decompression is still an issue. Will check with Mac developers.</p>\r\n<p>thanks again.</p>",
    "PostedDate": "2010-03-15T12:07:24.063-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "418384",
    "ThreadId": "205006",
    "Html": "<p>One more question.</p>\r\n<p>should I condsider changing this code if there are subfolders in a folder that&nbsp;i am&nbsp;about to zip and download?</p>",
    "PostedDate": "2010-03-15T12:34:12.367-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "418392",
    "ThreadId": "205006",
    "Html": "<p>ok, let me ask you - what do you mean by &quot;decompression does not work&quot; ?</p>\r\n<p>Another user has reported problems opening zip files on the mac, that are produced this way. I don't recommend reading the thread, because it is&nbsp;even more confusing to read it, than it was to participate in it, but here it is:&nbsp;(<a href=\"http://dotnetzip.codeplex.com/Thread/View.aspx?ThreadId=59740\">http://dotnetzip.codeplex.com/Thread/View.aspx?ThreadId=59740</a>).&nbsp; The working theory that I developed, but never confirmed, after that discussion, was that &quot;the bit 3 option&quot; in the zip file was causing a compatibility issue with Macintosh tools.</p>\r\n<p>The &quot;bit 3&quot; is always turned on in a zipfile that you write to a non-seekable output stream, which is what Response.OutputStream is.&nbsp;</p>\r\n<p>The way to get a zip file without bit 3 is to write the zipfile to a seekable stream.&nbsp; Two examples of this are:&nbsp; a MemoryStream, or a FileStream (representing a filesystem file).&nbsp;</p>\r\n<p>This is worth a try.&nbsp; If you use the &nbsp; MemoryStream idea, then your code looks like this:</p>\r\n<div style=\"border:solid .1em #ccc;color:Black;background-color:White;margin:.25em 1em 0 1em;padding:0 .25em 0 .25em\">\r\n<pre><span style=\"color:Blue\">Private</span> <span style=\"color:Blue\">Sub</span> ZipFolder(<span style=\"color:Blue\">ByVal</span> FolderToZip <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">String</span>)\r\n    Response.Clear()\r\n    Response.BufferOutput = <span style=\"color:Blue\">False</span>\r\n\r\n    <span style=\"color:Blue\">Dim</span> archiveName <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">String</span> = _\r\n        Path.GetFileName(FolderToZip) &amp; <span style=\"color:#A31515\">&quot;_&quot;</span> &amp; (DateTime.Now.ToString(<span style=\"color:#A31515\">&quot;yyyyMMMdd_HHmmss&quot;</span>)) &amp; <span style=\"color:#A31515\">&quot;.zip&quot;</span>\r\n\r\n    Response.ContentType = <span style=\"color:#A31515\">&quot;application/zip&quot;</span>\r\n    Response.AddHeader(<span style=\"color:#A31515\">&quot;Content-Disposition&quot;</span>, <span style=\"color:#A31515\">&quot;filename=&quot;</span> &amp; chr(34) &amp; archiveName &amp; chr(34))\r\n\r\n    <span style=\"color:Blue\">Using</span> ms <span style=\"color:Blue\">as</span> <span style=\"color:Blue\">New</span> System.IO.MemoryStream()\r\n        <span style=\"color:Blue\">Using</span> zip <span style=\"color:Blue\">As</span> ZipFile = <span style=\"color:Blue\">New</span> ZipFile()\r\n            zip.AddDirectory(FolderToZip)\r\n            <span style=\"color:Green\">'' save the zip fiel to a memory stream</span>\r\n            zip.Save(ms)\r\n        <span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Using</span>\r\n        <span style=\"color:Green\">'' now copy the memory stream to the Response OutputStream</span>\r\n        ms.Position = 0\r\n        <span style=\"color:Blue\">dim</span> b(1024) <span style=\"color:Blue\">as</span> <span style=\"color:Blue\">Byte</span>\r\n        <span style=\"color:Blue\">dim</span> n <span style=\"color:Blue\">as</span> <span style=\"color:Blue\">new</span> Int32\r\n        n=-1\r\n        <span style=\"color:Blue\">While</span> (n &lt;&gt; 0)\r\n            n = ms.Read(b,0,b.Length)\r\n            <span style=\"color:Blue\">If</span> (n &lt;&gt; 0)\r\n                Response.OutputStream.Write(b,0,n)\r\n            <span style=\"color:Blue\">End</span> <span style=\"color:Blue\">If</span>\r\n        <span style=\"color:Blue\">End</span> <span style=\"color:Blue\">While</span>\r\n        Response.Close\r\n    <span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Using</span>\r\n    Response.Close()\r\n<span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Sub</span>\r\n\r\n</pre>\r\n</div>\r\n<p>In this case, the entire contents of the compressed zip will be placed into memory, before writing it out to Response.OutputStream.&nbsp; This may or may not be acceptable to you, depending on how large the zip file is.</p>\r\n<p>If you use the FileStream idea, then your code would look like this:</p>\r\n<div style=\"border:solid .1em #ccc;color:Black;background-color:White;margin:.25em 1em 0 1em;padding:0 .25em 0 .25em\">\r\n<pre><span style=\"color:Blue\">Private</span> <span style=\"color:Blue\">Sub</span> ZipFolder(<span style=\"color:Blue\">ByVal</span> FolderToZip <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">String</span>)\r\n    Response.Clear()\r\n    Response.BufferOutput = <span style=\"color:Blue\">False</span>\r\n\r\n    <span style=\"color:Blue\">Dim</span> archiveName <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">String</span> = _\r\n        Path.GetFileName(FolderToZip) &amp; <span style=\"color:#A31515\">&quot;_&quot;</span> &amp; (DateTime.Now.ToString(<span style=\"color:#A31515\">&quot;yyyyMMMdd_HHmmss&quot;</span>)) &amp; <span style=\"color:#A31515\">&quot;.zip&quot;</span>\r\n\r\n    Response.ContentType = <span style=\"color:#A31515\">&quot;application/zip&quot;</span>\r\n    Response.AddHeader(<span style=\"color:#A31515\">&quot;Content-Disposition&quot;</span>, <span style=\"color:#A31515\">&quot;filename=&quot;</span> &amp; chr(34) &amp; archiveName &amp; chr(34))\r\n    <span style=\"color:Blue\">Dim</span> tempfile <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">String</span> = <span style=\"color:#A31515\">&quot;c:\\temp\\&quot;</span> &amp; archiveName\r\n    <span style=\"color:Blue\">Using</span> zip <span style=\"color:Blue\">As</span> ZipFile = <span style=\"color:Blue\">New</span> ZipFile()\r\n        zip.AddDirectory(FolderToZip)\r\n        <span style=\"color:Green\">'' save the zip fiel to a memory stream</span>\r\n        zip.Save(tempfile)\r\n    <span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Using</span>\r\n    <span style=\"color:Green\">' open and read the file, and copy it to Response.OutputStream</span>\r\n    <span style=\"color:Blue\">Using</span> fs <span style=\"color:Blue\">as</span> System.IO.FileStream = System.IO.File.OpenRead(tempfile)\r\n        <span style=\"color:Blue\">dim</span> b(1024) <span style=\"color:Blue\">as</span> <span style=\"color:Blue\">Byte</span>\r\n        <span style=\"color:Blue\">dim</span> n <span style=\"color:Blue\">as</span> <span style=\"color:Blue\">New</span> Int32\r\n        n=-1\r\n        <span style=\"color:Blue\">While</span> (n &lt;&gt; 0)\r\n            n = fs.Read(b,0,b.Length)\r\n            <span style=\"color:Blue\">If</span> (n &lt;&gt; 0)\r\n                Response.OutputStream.Write(b,0,n)\r\n            <span style=\"color:Blue\">End</span> <span style=\"color:Blue\">If</span>\r\n        <span style=\"color:Blue\">End</span> <span style=\"color:Blue\">While</span>\r\n    <span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Using</span>\r\n    Response.Close\r\n    System.IO.File.Delete(tempfile)\r\n<span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Sub</span>\r\n\r\n</pre>\r\n</div>\r\n<p>Try one of those and see if it works for you.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-03-15T12:58:10.057-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]