Search code examples
excelfirefoxopenxmlhttpresponseresponse.write

Sending Excel file to User working with Chrome and IE but not firefox(Get file with no extension)


I am generating and excel file using the OpenXML library and sending it to the user. It works very well with Chrome and IE but when i tried it with Firefox i came upon a problem.

When saving the file using FF i get a File with no extension When opening the file using FF it works like a charm :(

I am using the following function to send the stream to the user.

public static void SendToClient(Byte[] stream, string fileName)
{
    HttpContext.Current.Response.ClearContent();
    HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
    HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

    HttpContext.Current.Response.BinaryWrite(stream);
    HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + fileName + ".xlsx");
    HttpContext.Current.Response.AddHeader("content-length", stream.LongLength.ToString());
    HttpContext.Current.Response.End();
}

and calling it like this:

_ExcelReports.SendToClient(excelUtil.ExportToExcel(excelWorkBook), projectName + " Resources");

Even weirder, FF download dialog recognizes the file, like in screenshot:

FF download dialog

Now for the completed download:

FF completed downloads


Solution

  • Have you tried using contentType = "application/vnd.ms-excel" ?

    I'm a newbie with bigger problems figuring out what I'm trying to do, but the little bit that I have working is using that content type.