I have some code in a button click event which gets a csv string from a hidden input and writes it to the response as a CSV file.
This work fine in Chrome, Firefox, ie7, ie9 in quirks mode. However it does not work in ie8 or ie9 default.
Looking at this in fiddler the csv is being written to the response but the another get request is being made immediately after and the page reloads. No file saving dialog appears.
protected void btnCsvHidden_Click(object sender, EventArgs e)
{
var csv = csvString.Value;
var filename = "Reporting";
Response.Clear();
Response.ClearHeaders();
Response.AddHeader("Cache-Control", "no-store, no-cache");
Response.AddHeader("content-disposition", "attachment; filename=\"" + filename + ".csv\"");
Response.ContentType = "text/csv";
Response.Write(csv);
Response.End();
}
The problem was with my own IE, I ran a load of windows updates and now it works so I'm not sure what it was exactly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With