我需要编写一个过程来在我的 vb.net Web 应用程序中本地下载 html 文件。我目前正在使用 webClient.DownloadFile :

Dim myWebClient As New System.Net.WebClient
myWebClient.DownloadFile("http://archive.ncsa.illinois.edu/primer.html", _
                        "C:\test.html")

是否有一种内置方法可以通过“另存为”窗口来执行此操作,以便用户可以选择他们想要将文件保存到的位置?或者我需要自己写?

有帮助吗?

解决方案

您可以使用

Response.AddHeader("Content-Disposition", "attachment;filename=testfile_file.html");
Response.Write or Response.WriteFile

其他提示

虽然我意识到这不是您问题的答案(请参阅托马斯答案的评论),但有时保持简单是一个好方法

Please right-click this link and save the file
<a href=""http://archive.ncsa.illinois.edu/primer.html">HTML Primer</a>

尝试下面的代码

Response.ContentType = "report/rpt";

Response.AppendHeader("Content-Disposition", "attachment; filename=CrystalReport1.rpt");

Response.TransmitFile(Server.MapPath("CrystalReport1.rpt"));

Response.End();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top