CSV file download ignored in ie8/9

Posted by JBB on Stack Overflow See other posts from Stack Overflow or by JBB
Published on 2012-12-19T17:04:17Z Indexed on 2012/12/19 23:03 UTC
Read the original article Hit count: 152

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();
    }

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET