Want more features on Pastebin? Sign Up, it's FREE!
Guest

Why does IE fail to server my CSV file from Response.Write

By: a guest on Feb 21st, 2012  |  syntax: None  |  size: 1.33 KB  |  views: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Response.Clear();
  2.  
  3.  Response.ContentType = "text/CSV";
  4.  
  5.  Response.CacheControl = "no-cache";
  6.  Response.AddHeader("Pragma", "no-cache");
  7.  Response.Expires = -1;
  8.  
  9.  Response.AddHeader("Pragma", "must-revalidate");
  10.  Response.AddHeader("Cache-Control", "must-revalidate");
  11.  Response.AddHeader("Accept-Header", csvResults.Length.ToString());
  12.  Response.AddHeader("Content-Length", csvResults.Length.ToString());
  13.  Response.AddHeader("content-disposition", "attachment; filename=test.csv");
  14.  Response.Write(csvResults.ToString());
  15.  Response.Flush();
  16.  Response.End();
  17.        
  18. protected void Application_BeginRequest(Object sender, EventArgs e)
  19.     {
  20.         string requestURL = Request.Url.ToString().ToLower();
  21.         if (requestURL.StartsWith("http://"))
  22.         {
  23.             Response.Redirect(requestURL.Replace("http:", "https:"));
  24.         }
  25.     }
  26.        
  27. HTTP/1.1 200 OK
  28. Date: Tue, 09 Nov 2010 14:23:50 GMT
  29. Server: Microsoft-IIS/6.0
  30. X-Powered-By: ASP.NET
  31. X-AspNet-Version: 4.0.30319
  32. Pragma: no-cache
  33. Pragma: must-revalidate
  34.  
  35. content-disposition: attachment; filename="test.csv"
  36. Cache-Control: no-cache
  37. Pragma: no-cache
  38. Expires: -1
  39. Content-Length: <length value would be here>
  40. Content-Type: text/CSV
  41.  
  42. "COL1","COL2","COL3"
  43. "VAL1","VAL2","VAL3"
  44. "VAL1","VAL2","VAL3"
  45. "VAL1","VAL2","VAL3"
  46.        
  47. Response.ClearHeaders();
  48. Response.AddHeader("Cache-Control", "no-store, no-cache");
clone this paste RAW Paste Data