当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - How to have Internet Explorer hold on to a stream?

问题描述:

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);
分享给朋友:
您可能感兴趣的文章:
随机阅读: