Question posted 2012 · +5 upvotes
I’m playing around with EPPlus 2.9 and for some reason I’m getting Duplicate headers received from server errors when I try to download single .xlsx files using Chrome 16 (It works fine in IE9).
I’m using this tutorial and I’ve narrowed down the problem to this line of code:
Response.AppendHeader("Content-Disposition",
"attachment; " +
"filename="ExcelReport.xlsx"; " +
"size=" + fileBytes.Length.ToString() + "; " +
"creation-date=" + DateTime.Now.ToString("R") + "; " +
"modification-date=" + DateTime.Now.ToString("R") + "; " +
"read-date=" + DateTime.Now.ToString("R"));
My useragent:
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7
I read on this Chrome forum page that Chrome doesn’t like commas (,) in Content-Disposition headers and they should be replaced with semicolons (;).
Anybody got any ideas or getting the same errors?
Accepted answer +9 upvotes
I’m dumb, DateTime.Now.ToString("R") produces Thu, 26 Jan 2012 02:05:44 GMT
I fixed it by doing this:
String timestamp_without_commas = DateTime.Now.ToString("R").Replace(",","");
Response.AppendHeader("Content-Disposition",
"attachment; " +
"filename="ExcelReport.xlsx"; " +
"size=" + fileBytes.Length.ToString() + "; " +
"creation-date=" + timestamp_without_commas + "; " +
"modification-date=" + timestamp_without_commas + "; " +
"read-date=" + timestamp_without_commas);
I’m used to IE being cranky and Chrome playing nice…
Top excel Q&A (6)
- Shortcut to Apply a Formula to an Entire Column in Excel +335 (2011)
- How should I escape commas and speech marks in CSV files so they work in Excel? +136 (2012)
- Convert xlsx to csv in linux command line +96 (2012)
- How to create a link inside a cell using EPPlus +50 (2011)
- IF statement: how to leave cell blank if condition is false ("" does not work) +44 (2013)
- T-SQL: Export to new Excel file +44 (2012)
excel solutions on this site
.