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.ContentType = "text/plain"
Response.AddHeader("Content-disposition", "inline; filename=" + summaryFilename + ".csv")

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

Posted by Kartones on 2009-10-18

Comments? Share via Twitter Share via Linkedin