[
  {
    "Id": "427698",
    "ThreadId": "208410",
    "Html": "<p>Hi Everyone,</p>\r\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; I have used below code to zip and&nbsp; download files&nbsp;&nbsp; which works perfectly in IIS and IIS6 but fails to work in IIS7. A window will open and blank out. Please anyone could help me out with this.Below is my code.Thanks in advance... &nbsp;&nbsp;&nbsp;</p>\r\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; HttpContext.Current.Response.Clear();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string archiveName = String.Format(&quot;Records-{0}.zip&quot;, DateTime.Now.ToString(&quot;yyyy-MMM-dd-HHmmss&quot;));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpContext.Current.Response.ContentType = &quot;application/zip&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpContext.Current.Response.AddHeader(&quot;content-disposition&quot;, &quot;filename=&quot; + archiveName);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Query<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using (ZipFile zip = new ZipFile())<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string tempDirectory = &quot;c:\\\\Files&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DirectoryInfo di = new DirectoryInfo(tempDirectory);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileInfo[] rgFiles = di.GetFiles();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (FileInfo fi in rgFiles)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zip.AddFile(fi.FullName, &quot;Records&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zip.Save(HttpContext.Current.Response.OutputStream);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpContext.Current.Response.End();</p>\r\n<p>&nbsp;</p>\r\n<p>Regards,</p>\r\n<p>Shamveel.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-04-05T22:20:02.213-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "427821",
    "ThreadId": "208410",
    "Html": "<p>Shamveel, try to use RequestComplete in place of Response.End().&nbsp; Something like this:</p>\r\n<div style=\"border:solid .1em #ccc;color:Black;background-color:White;margin:.25em 0.5em 0 0.5em;padding:0.25em 1.75em 0.25em 1.25em\">\r\n<pre>System.Web.HttpContext c= System.Web.HttpContext.Current;\r\nc.Response.Clear();\r\nc.Response.BufferOutput= <span style=\"color:Blue\">false</span>;\r\n<span style=\"color:Blue\">string</span> archiveName= String.Format(<span style=\"color:#A31515\">&quot;archive-{0}.zip&quot;</span>, DateTime.Now.ToString(<span style=\"color:#A31515\">&quot;yyyy-MMM-dd-HHmmss&quot;</span>));\r\nc.Response.ContentType = <span style=\"color:#A31515\">&quot;application/zip&quot;</span>;\r\nc.Response.AddHeader(<span style=\"color:#A31515\">&quot;content-disposition&quot;</span>, <span style=\"color:#A31515\">&quot;inline; filename=\\&quot;&quot;</span> + archiveName + <span style=\"color:#A31515\">&quot;\\&quot;&quot;</span>);\r\n\r\n<span style=\"color:Blue\">using</span> (ZipFile zip = <span style=\"color:Blue\">new</span> ZipFile())\r\n{\r\n    <span style=\"color:Blue\">string</span> tempDirectory = <span style=\"color:#A31515\">&quot;c:\\\\Files&quot;</span>;\r\n    DirectoryInfo di = <span style=\"color:Blue\">new</span> DirectoryInfo(tempDirectory);\r\n    FileInfo[] rgFiles = di.GetFiles();\r\n    <span style=\"color:Blue\">foreach</span> (FileInfo fi <span style=\"color:Blue\">in</span> rgFiles)\r\n    {\r\n        zip.AddFile(fi.FullName, <span style=\"color:#A31515\">&quot;Records&quot;</span>);\r\n    }\r\n    zip.Save(c.Response.OutputStream);\r\n}\r\nc.ApplicationInstance.CompleteRequest();</pre>\r\n</div>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-04-06T05:29:36.997-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "427854",
    "ThreadId": "208410",
    "Html": "<p>Hi Cheeso..</p>\r\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thank you for your reply. I will try the method mentioned by you.Forgot to mentioned that the download functionality working fine in Mozilla. In IE browser doesn't work.</p>\r\n<p>&nbsp;</p>\r\n<p>Regards</p>\r\n<p>Shamveel.</p>",
    "PostedDate": "2010-04-06T07:02:05.137-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "427867",
    "ThreadId": "208410",
    "Html": "<p>Hi Cheeso,</p>\r\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; No luck... :( . I couldn't understand this behavior...</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-04-06T07:26:53.103-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "427872",
    "ThreadId": "208410",
    "Html": "<p>Hey cheeso,</p>\r\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I got a chance to test the same in the server ( i mean locally..ex&quot;http://localhost/app/ ) .The functionality works fine ther.. If i try to do the same from my machine it doesnt work ( IE browser)</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-04-06T07:36:03.237-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "427879",
    "ThreadId": "208410",
    "Html": "<p>If that's true, then it could be a matter of caching.&nbsp; Try inserting a Response.Flush() before the call to CompleteRequest().</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-04-06T07:47:39.603-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "427956",
    "ThreadId": "208410",
    "Html": "<p>Its not working cheeso. I feel like some thing we need to do in&nbsp; &quot; zip.Save(c.Response.OutputStream); &quot; were the file will be given as output. I couldnt understand where to do wat.Just wondering how does it works in Mozilla..?&nbsp;</p>",
    "PostedDate": "2010-04-06T10:45:02.207-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "427972",
    "ThreadId": "208410",
    "Html": "<p>&gt; .Just wondering how does it works in Mozilla..?</p>\r\n<p>That's what I mean by, <em>it could be&nbsp;a matter of caching.</em></p>\r\n<p>If I were debugging this, I would look at the returned bytestream, via Fiddler or some other trace tool.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-04-06T11:26:36.29-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "427973",
    "ThreadId": "208410",
    "Html": "<p>Sure cheeso, i will do whatever you want me to.Will get back to you&nbsp; by tomorrow with the fiddler output.. Thanks..</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-04-06T11:32:16.503-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "428175",
    "ThreadId": "208410",
    "Html": "<p>Hey Cheeso,</p>\r\n<p>Below is the output what i recieved from fiddler:</p>\r\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<strong> IIS6: Which works fine</strong></p>\r\n<p>&nbsp;</p>\r\n<p>HTTP/1.1 200 OK<br>Cache-Control: private<br>Content-Length: 565055<br>Content-Type: application/zip<br>Server: Microsoft-IIS/6.0<br>MicrosoftSharePointTeamServices: 6.0.2.5530<br>X-Powered-By: ASP.NET<br>X-AspNet-Version: 2.0.50727<br>content-disposition: filename=Records-2010-Apr-07-120740.zip<br>Date: Wed, 07 Apr 2010 06:37:40 GMT<br>Connection: close</p>\r\n<p>&nbsp;</p>\r\n<p><strong>IIS7:(In our server which works fine )</strong></p>\r\n<p>HTTP/1.1 200 OK<br>Cache-Control: private<br>Content-Type: application/zip<br>Server: Microsoft-IIS/7.0<br>content-disposition: filename=Records-2010-Apr-07-122616.zip<br>X-AspNet-Version: 2.0.50727<br>X-Powered-By: ASP.NET<br>Date: Wed, 07 Apr 2010 06:56:15 GMT<br>Content-Length: 405526</p>\r\n<p><strong>IIS7:(In hosting server where doesnt work)</strong></p>\r\n<p>HTTP/1.1 200 OK<br>Cache-Control: private<br>Content-Type: application/zip<br>Server: Microsoft-IIS/7.0<br>content-disposition: filename=Records-2010-Apr-07-123202.zip<br>X-AspNet-Version: 2.0.50727<br>X-Powered-By: ASP.NET<br>Date: Wed, 07 Apr 2010 07:02:02 GMT<br>Content-Length: 3201039</p>\r\n<p>&nbsp;</p>\r\n<p>Let me know if you need more information..&nbsp; Thanx..</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-04-07T00:12:43.03-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "428473",
    "ThreadId": "208410",
    "Html": "<p>Mmm, yes, so the headers are virtually identical.</p>\r\n<p>One question:&nbsp; why are the content-length values so different?&nbsp;Did you zip the same file each time?&nbsp; In that case, there's a cause for concern, and evidence of a difference.&nbsp; It doesn't explain the difference, but it&nbsp;&nbsp;makes it pretty clear.&nbsp; On the other hand, maybe you zipped different files in each case.&nbsp; If that were true, then the differing content-length would be expected.</p>\r\n<p>Beyond on the headers, I'm really more interested in the data that follows.&nbsp; Did you get all the data, in each case?&nbsp;&nbsp; Does Fiddler indicate that all of the data arrived?</p>\r\n<p>It may be easier to troubleshoot this if you reduce the size of the zip that is generated. on the other hand that may also cause the problem to disappear.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-04-07T12:34:07.857-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "428494",
    "ThreadId": "208410",
    "Html": "<p>Another thing -</p>\r\n<p>have you set the buffering off, and cleared the headers before beginning the transfer? IT should look something like this:</p>\r\n<div style=\"border:solid .1em #ccc;color:Black;background-color:White;margin:.25em 0.5em 0 0.5em;padding:0.25em 1.75em 0.25em 1.25em\">\r\n<pre>    c.Response.Clear();\r\n    c.Response.ClearHeaders();\r\n    c.Response.BufferOutput= false;</pre>\r\n</div>\r\n<p>This should appear before writing anything to the response stream.</p>\r\n<p>Here's the thing - the HTTP protocol provides a mechanism by which a server can tell a client (browser) how much data is coming. This is the Content-Length header.&nbsp; This is known for small transfers, let's say an HTML page that is generated from&nbsp;ASP.NET , and is about 8k in length.&nbsp; The way it works is, the ASPNET runtime caches the response, and determines the size of it, before sending any of the response to the requesting client. &nbsp;For large responses, like a binary file, or a dynamically-generated zip file, the ASPNET runtime cannot possibly cache all that data.&nbsp; So the size of the data is not known, at the time the first few bytes are sent, which means ASPNET cannot respond with a Content-Length header.</p>\r\n<p>The HTTP specification allows for this, using what's called &quot;chunked&quot; Transfer-Encoding. Instead of caching the response, determining the size, and injecting a &quot;Content-Length&quot; header into the response, before sending it in its entirety, with chunked encoding, ASPNET injects a header like &quot;Transfer-Encoding: Chunked&quot; , and then begins transmitting the data.&nbsp; The data arrives in chunks, each chunk marked with headers.&nbsp; The final chunk is marked specially.&nbsp; The client stops downloading after receiving this specially-marked chunk.&nbsp; This is all documented in the HTTP spec.&nbsp;</p>\r\n<p>ASP.NET handles the chunking for you automatically, when using chunked encoding.&nbsp; So the question is, how to turn on chunked encoding?&nbsp; With other headers you can simply call <span style=\"font-family:Courier\">Response.AddHeader(&quot;transfer-encoding&quot;, &quot;chunked&quot;);&nbsp;</span>&nbsp; But this is not permitted by ASPNET, for that header.&nbsp; So you have to do it implicitly. &nbsp;Setting the buffering to false should do it.&nbsp; It should also work to call Flush() on the ResponseStream, at any point after having written <em>something</em> to the Response stream, and before the final close of the stream.&nbsp; That really isn't possible when saving a file to the stream, as is the case in dynamically generating a zip file with DotNetZip, so you'll have to use the <span style=\"font-family:Courier\">BufferOutput=false;</span> thing. The resulting response headers should look like this:</p>\r\n<div style=\"border:solid .1em #ccc;color:Black;background-color:White;margin:.25em 0.5em 0 0.5em;padding:0.25em 1.75em 0.25em 1.25em\">\r\n<pre>HTTP/1.1 200 OK\r\nCache-Control: private\r\n<span style=\"color:red\">Transfer-Encoding: chunked</span>\r\nContent-Type: application/zip\r\nServer: Microsoft-IIS/7.0\r\ncontent-disposition: inline; filename=&quot;archive-2010-Apr-07-160954.zip&quot;\r\nX-AspNet-Version: 2.0.50727\r\nX-Powered-By: ASP.NET\r\nDate: Wed, 07 Apr 2010 20:09:54 GMT</pre>\r\n</div>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-04-07T13:16:40.433-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "429908",
    "ThreadId": "208410",
    "Html": "<p>Hey Cheeso,</p>\r\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sorry for the late reply as i was busy with my other schedule. The content length difference is mainly becoz of the number of files ; if you go by one file also application wont pop up for download. I have used the above method mentioned by you still its the same.Here is the fiddler output.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>\r\n<p>HTTP/1.1 200 OK<br>Cache-Control: private<br>Transfer-Encoding: chunked<br>Content-Type: application/zip<br>Server: Microsoft-IIS/7.0<br>content-disposition: inline; filename=&quot;Records-2010-Apr-12-130825.zip&quot;<br>X-AspNet-Version: 2.0.50727<br>X-Powered-By: ASP.NET<br>Date: Mon, 12 Apr 2010 07:38:25 GMT</p>\r\n<p>And i wanted to know that why it acts differently in two machines ( i mean when i used in our local server-IIS7 it works fine ,only in hosting server this is the issue-that too only when we access it through IE)</p>\r\n<p>Thanx...</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-04-12T00:43:23.153-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "430032",
    "ThreadId": "208410",
    "Html": "<blockquote style=\"border:solid .1em #ccc;font-style:italic;margin:.25em 1em 0 1em;padding:0 .25em 0 .25em\"><strong>shamveel wrote:</strong><br>\r\n<p>And i wanted to know that why it acts differently in two machines ( i mean when i used in our local server-IIS7 it works fine ,only in hosting server this is the issue-that too only when we access it through IE)</p>\r\n</blockquote>\r\n<p>Yes, I have a theory that the difference you're seeing is because of a problem with the caching.&nbsp; This is why I said that the Fiddler information would be interesting. Once again, it's not only the headers that are the interesting part.&nbsp; You should also be interested in the actual length of content that is returned, for the case that works properly, as well as for the case that doesn't work properly.</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-04-12T07:44:39.493-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "464935",
    "ThreadId": "208410",
    "Html": "<p>Could this have anything to do with some of the native compression in IIS7 that is not turned on in IIS6.&nbsp; I am attempting to configure IIS Compression on IIS6, and after I update the MetaBase.xml with the compression setting I can no longer get the zip files with work.&nbsp; They will download from the site, but when you try and open the file it says the zip file is invalid.&nbsp; If I remove the compression settings it works fine.&nbsp; Any thoughts.&nbsp; I might create a seperate thread just thought this sounded similiar.</p>\r\n<p><a href=\"http://dotnetzip.codeplex.com/Thread/View.aspx?ThreadId=218795\">http://dotnetzip.codeplex.com/Thread/View.aspx?ThreadId=218795</a></p>",
    "PostedDate": "2010-07-08T09:15:01.5-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]