Title: ASP.NET: Flushing files to browser with Response.AddHeader()
Slug: asp-net-flushing-files-to-browser-with-response-addheader
Date: 2009-10-18 13:49:00
Author: Kartones
Lang: en
Tags: Development, ASP.NET, Troubleshooting
Description: A guide on fixing content flushing issues in ASP.NET

 <p>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).</p>  <p>Probably because of the configuration of IIS, the content header was not being applied correctly with <font face="Courier New">Response.AppendHeader()</font>, so just changing it to <font face="Courier New">Response.AddHeader()</font> it was solved.</p>  <p><font color="#000000" face="Courier New">Response.Clear()</font><font face="Courier New"><font color="#0000ff">;        <br></font><font color="#000000">Response.ClearHeaders()</font></font><font face="Courier New"><font color="#0000ff">;        <br></font><font color="#000000">Response.ClearContent()</font></font><font face="Courier New"><font color="#0000ff">;        <br></font><font color="#000000">Response.ContentType </font><font color="#0000ff">= </font><font color="#808080">"text/plain"</font></font><font face="Courier New"><font color="#0000ff">;        <br></font><font color="#000000">Response.AddHeader(</font><font color="#808080">"Content-disposition"</font><font color="#000000">, </font><font color="#808080">"inline; filename=" </font><font color="#000000">+ summaryFilename + </font><font color="#808080">".csv"</font><font color="#000000">)</font></font><font face="Courier New"><font color="#0000ff">;        <br></font><font color="#000000">Response.Write(summaryResults)</font></font><font face="Courier New"><font color="#0000ff">;        <br></font><font color="#000000">Response.End()</font><font color="#0000ff">;</font></font></p>  <p> </p>  <p>So, if <i>AppendHeader</i> doesn't work as it should, give a try to <i>AddHeader</i>. </p>
