流回csv文件时进度未关闭

本文关键字:csv 文件 流回 | 更新日期: 2023-09-27 18:17:35

我有一个更新面板,在里面,我已经放置了许多控件,如ajax updateprogress,单选按钮和FileUpload控件。最后有两个按钮,一个保存数据,另一个生成xml数据。

生成xml时,我以以下代码流返回屏幕,

 Response.Clear();
 Response.ClearContent();
 Response.ClearHeaders();
 Response.ContentType = "application/xml";
 Response.AddHeader("Content-Disposition", "attachment; filename=" + filePath);
 Response.TransmitFile(filePath);
 Response.End();

此时,更新进度映像没有被关闭。有人能帮我吗?

流回csv文件时进度未关闭

因为当文件发送到客户端时响应已经结束。你需要在新的页面做。

中替换你的代码:

Session["filePath"] = filePath;
ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "var Mleft = (screen.width/2)-(760/2);var Mtop = (screen.height/2)-(700/2);window.open( 'file.aspx', null, 'height=700,width=760,status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no,top=''+Mtop+'', left=''+Mleft+''' );", true);

新页面(名为"file.aspx"):

protected void Page_Load(object sender, EventArgs e)
{
     Response.Clear();
     Response.ClearContent();
     Response.ClearHeaders();
     Response.ContentType = "application/xml";
     Response.AddHeader("Content-Disposition", "attachment; filename=" +  Session["filePath"].ToString());
     Response.TransmitFile(Session["filePath"].ToString());
     Response.End();
}