VB.net 文件下载阻止回发

发布于 2024-11-01 19:02:31 字数 573 浏览 9 评论 0原文

我想生成一个(报告)文件供用户下载,然后向用户显示一条消息以显示该过程已成功完成。

Dim myFile As FileInfo = New FileInfo(<filepath>)

'My function to generate a report (this can take a few minutes)
GenerateReport(myFile.FullName)

'Prompt user with "save as" dialog box.
Response.Clear()
Response.ClearHeaders()
Response.AddHeader("Content-Disposition", "attachment; filename=" & _
Response.WriteFile()

'Give message to say generation is complete. (This line doesn't take effect)
lblMsg.Text = "Generation complete"

但是,当我使用创建“另存为”框时,它似乎根本停止显示消息。这是为什么?谁能建议一种解决方法?

I want to generate a (report) file for users to download, then display a message to users to show the process completed successfully.

Dim myFile As FileInfo = New FileInfo(<filepath>)

'My function to generate a report (this can take a few minutes)
GenerateReport(myFile.FullName)

'Prompt user with "save as" dialog box.
Response.Clear()
Response.ClearHeaders()
Response.AddHeader("Content-Disposition", "attachment; filename=" & _
Response.WriteFile()

'Give message to say generation is complete. (This line doesn't take effect)
lblMsg.Text = "Generation complete"

However, when I use create a "save as" box, it seems to stop the message appearing at all. Why is that? And can anyone suggest a way around it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽清梦 2024-11-08 19:02:31

看来这是一个很常见的问题。但对于我遇到的所有建议,似乎很少有人提供任何解决方案。 这是 Rick Strahl 博客中的一篇有用的文章

一种有用的方法是 MyWebClient.DownloadFile。这可以正常下载文件,但不会根据需要提供“另存为”对话框。

It seems this is quite a common problem. But for all the suggestions I've come across, few seem to offer any sort of solution. Here's a useful article in Rick Strahl's blog.

One useful method is MyWebClient.DownloadFile. This downloads the file ok, but doesn't give a "save as" dialogue box as required.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文