I am streaming a CSV file to Internet Explorer. At the end of the streaming, Internet Explorer presents an Open, Save, and Cancel dialog. If you wait 30 seconds after the dialog is presented and click the Open button, Internet Explorer does nothing. This works fine in Firefox. Do I need some other command besides Flush and End on the Response? Here is the code that I have:
protected void Page_Load(object sender, EventArgs e){
DataTable dt = ReportService.GetAllOwnerAircraftPaymentInformation();
//Generate the report
using (MemoryStream stream = new MemoryStream())
{
StreamWriter writer = new StreamWriter(stream);
CsvHelper csvHelper = new CsvHelper();
csvHelper.DataTableToCsv(writer, dt);
writer.Flush();
//Send it to the browser
stream.Seek(0, SeekOrigin.Begin);
string fileName = string.Format("MassAVRMSDataExport{0}.csv", DateTime.Now.ToString("yyyyMMddhhmmss"));
Response.ClearHeaders();
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
Response.AddHeader("Content-Length", stream.Length.ToString(CultureInfo.InvariantCulture));
StreamHelper.CopyStream(stream, Response.OutputStream);
Response.Flush();
Response.End();
}
}
Greg you need to add the following when working with IE Explorer
Response.ContentType = "application/download"
Try setting:
stream.Position = 0;
StreamHelper.CopyStream(stream, Response.OutputStream);