Response.Flush writes HTML for page on Windows Vista, 7, 8 but not on Server 2008

SimpleHabbo

New Member
I'm generating a CSV from a link on the page and sending it back to the user. I wish to maintain the page context. This code works flawlessly for IE, Chrome and Firefox on my 2008 Dev box, however when run on Vista, Win 7 or Win 8 the file has the HTML for the page appended.I did a fair bit of reading regarding the method for delivering a file and concluded that response.flush() was the best way to go.\[code\] // Convert to Bytes for Binary Write Byte[] bytes = Utils.Instance.ReadStreamToByte(streamWriter.BaseStream); // Call ContentType followed by clear so no extraneous content is sent. see http://msdn.microsoft.com/en-us/library/system.web.httpresponse.aspx HttpContext.Current.Response.ContentType = "text/csv"; HttpContext.Current.Response.Clear(); HttpContext.Current.Response.AppendHeader("content-length", bytes.Length.ToString()); HttpContext.Current.Response.AppendHeader("content-Disposition", "attachment;filename=" + "MyAccount Sales Report " + MonthDDL.SelectedItem.Text + "-" + YearDDL.SelectedItem.Text + ".csv"); HttpContext.Current.Response.BinaryWrite(bytes); HttpContext.Current.Response.Flush();\[/code\]I've searched for why this is occuring and are yet to find any relevant help. I did change the positioning of the Clear(); as per the Microsoft article listed in the comment above but this had no affect.
 
Back
Top