如何让Internet Explorer保留流
本文关键字:保留 Explorer Internet | 更新日期: 2023-09-27 17:58:45
我正在将CSV文件流式传输到Internet Explorer。在流式传输结束时,Internet Explorer会显示"打开"、"保存"answers"取消"对话框。如果在对话框显示后等待30秒,然后单击"打开"按钮,则Internet Explorer不会执行任何操作。这在Firefox中运行良好。除了在响应上刷新和结束之外,我还需要其他命令吗?这是我的代码:
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使用IE Explorer 时需要添加以下内容
Response.ContentType = "application/download"
尝试设置:
stream.Position = 0;
StreamHelper.CopyStream(stream, Response.OutputStream);