ASP.NET: Flushing files to browser with Response.AddHeader()

This post should be nothing new for people used to ASP.NET 2.0 or higher, but at my last job I had to fix a summary download page that was not flushing correctly the content to the browser (it appeared as downloading the .aspx page instead of a csv file).

Probably because of the configuration of IIS, the content header was not being applied correctly with Response.AppendHeader(), so just changing it to Response.AddHeader() it was solved.

Response.Clear();
Response.ClearHeaders()
;
Response.ClearContent()
;
Response.ContentType = "text/plain"
;
Response.AddHeader("Content-disposition", "inline; filename=" + summaryFilename + ".csv")
;
Response.Write(summaryResults)
;
Response.End();

 

So, if AppendHeader doesn’t works as it should, give a try to AddHeader.

Comments

No Comments

Leave a Comment

Title (required)  
Name (required)  
Your Website/Blog (optional)
Your Comment (required)  

Captcha
Enter the number of digits on the image above (required)