在我们的一个项目中,我们需要将文件从服务器下载到客户端的功能 .
为此,我们使用ashx处理程序来执行操作 . 它工作得很好,我们可以下载文件 .
现在我们需要一个需求,就像我们需要在下载开始和完成时更新字段 . 有没有办法做到这一点 .
一旦我们点击下载链接,将出现另存为对话框,之后我认为我们没有任何控制来检查进度 . 我想我们甚至不知道点击了哪个按钮,即我们不知道用户是否被点击了“是”或“否” .
任何人都可以建议一种方法来了解下载何时开始以及何时完成?我们正在使用带有c#的Asp.Net 2.0 .
用于下载的处理程序如下
string fileUrl = string.Empty;
if (context.Request["fileUrl"] != null)
{
fileUrl = context.Request["fileUrl"].ToString();
}
string filename = System.IO.Path.GetFileName(fileUrl);
context.Response.ClearContent();
context.Response.ContentType = "application/exe";
context.Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", filename));
context.Response.TransmitFile(fileUrl);
context.Response.Flush();
该文件是从aspx页面方法下载的
private void DownloadExe()
{
string downloadUrl = "Test.exe");
Response.Redirect("Test.ashx?fileUrl=" + downloadUrl, false);
}