When I want to export a list of type IEnumerable from Chrome it gives me an error saying "Error: network error". I try it in Firefox and it works fine, it downloads the file. Does anyone know how to fix this, or have an alternative (another method to download the xls?)
private void ExportXls(IEnumerable list, string NameFile)
{
var workbook = new Workbook();
workbook.Worksheets.Add(new Worksheet("Datos"));
var worksheet = workbook.Worksheets[0];
var ws = worksheet;
ws.GenerateByIEnumerable(list);
HttpResponse response = System.Web.HttpContext.Current.Response;
response.Clear();
response.ContentType = "application/octet-stream";
response.AppendHeader("Content-Disposition", "attachment; filename=\"" + NameFile + "_" + DateTime.Now.ToString("yyyyMMdd") + ".xlsx" + "\"");
workbook.Save(response.OutputStream);
response.Flush();
response.Close();
response.End();
}
I was able to solve it by removing the
response.Close()
and changing theresponse.ContentType = "application/octet-stream"
to"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
;