检测文件下载完成
问题描述:
我必须显示一个模式弹出窗口,直到文件被下载.文件下载完成后不久,将打开一个确认框,询问下载是否成功?我怎样才能做到这一点?任何建议表示赞赏.
我使用这段代码将excel发送给响应对象...我一直在使用epplus.
asp.net 4.0 c#
I have to display a modal pop up until the file gets downloaded.Soon after the file download completes, a confirm box is opened,asking if the download was successful or not? How can I achieve this? any suggestion is appreciated.
I used this code to send excel to response object...I have been using epplus.
asp.net 4.0 c#
worksheet.Tables[0].ShowFilter = true;
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.Clear();
// HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
HttpContext.Current.Response.ContentType = "application/x-msexcel";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + strfileName + ".xlsx");
HttpContext.Current.Response.AddHeader("Content-Length", package.GetAsByteArray().Length.ToString());
//HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
HttpContext.Current.Response.ContentEncoding = System.Text.UTF8Encoding.UTF8;
if (HttpContext.Current.Response.IsClientConnected)
{
HttpContext.Current.Response.BinaryWrite(package.GetAsByteArray());
}
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();
答
您可以通过在页面上放置IFrame来实现.步骤如下:
1.用户单击文件下载按钮,将IFrame的src设置为下载文件的URL.
2.检测到iframe已成功加载,有许多实现可用.
3.甚至发生加载时,请执行确认Java脚本功能以询问用户下载是否成功.
希望对您有所帮助.
谢谢
罗希特(Rohit)
You can achieve this by having a IFrame on the page. Steps would be as such:
1. User Clicks on file download button, Set src of IFrame to a URL which downloads the file.
2. Detect that iframe has loaded successfully, many implementation available.
3. When Load even occurs execute confirm java-script function to ask user about the success of download.
I hope it helps.
Thanks
Rohit