Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I have an ASP.NET (Framework 2.0) website which generates a CSV file and propmpts the user to Save or Open this file (IE native pop-up window). Recently some users upgraded their IE to version 11 and they get the file with HTML as content and not the actual CSV-style rows.
This is working in IE9 and below.
Code for Response.BinaryWrite:
Response.Buffer = False
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", "attachment;filename=FileExport.csv")
Response.BinaryWrite(Session("nExport"))
Session("nExport") = Nothing
Response.Flush()
Response.Close()
Response.End()
' Session("nExport") contains Byte()
Expected file content:
NR;FirstName;LastName
1;Bilbo;Baggins
File content if I select Save or Open:
"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">"
"<html xmlns=""http://www.w3.org/1999/xhtml"" >"
<head><title>
" Export"
</title></head>
" <form name=""form1"" method=""post"" action=""nExport.aspx?ID=RGVwbjsu3GFyamkyMDEz"" id=""form1"">"
"<input type=""hidden"" name=""__VIEWSTATE"" id=""__VIEWSTATE"" value=""/wEPDwUJNzgzNDMwNTMzZGSmoL1exQ/68hIbp0DWxDDjlt6wAA=="" />"
</form>
</body>
</html>
Edit: additional information from the user is that another (similar) CSV file download is working correctly. I will have to investigate some more, code for both downloads is the same.
Edit 2:
It seems to be working on UAT server, the solution was removing Response.End and Response.Close and use HttpApplication.CompleteRequest, as per this question ie-10-file-download-issues. Will have to investigate more and try on production servers.
Dim httpApp As New HttpApplication
httpApp.CompleteRequest()
'Response.Close()
'Response.End()
I can confirm a working solution on the production server also. As the comment from stun in this answer suggests I left Response.Close and Response.End after CompleteRequest.
This is the new Response method:
Response.Buffer = False
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", "attachment;filename=FileExport.csv")
Response.BinaryWrite(Session("nExport"))
Session("nExport") = Nothing
Response.Flush()
HttpContext.Current.ApplicationInstance.CompleteRequest()
Response.Close()
Response.End()
Edit: just a fix, using HttpContext.Current not making a new HttpApplication.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.