3

我需要编写一个过程来在我的 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")

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

4

3 回答 3

5

您可以使用

Response.AddHeader("Content-Disposition", "attachment;filename=testfile_file.html");
Response.Write or Response.WriteFile
于 2011-05-13T10:16:21.393 回答
1

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

Please right-click this link and save the file
<a href=""http://archive.ncsa.illinois.edu/primer.html">HTML Primer</a>
于 2011-05-13T10:23:25.243 回答
0

试试下面的代码

Response.ContentType = "report/rpt";

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

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

Response.End();
于 2011-05-13T10:19:49.400 回答