Asp.net 使用“下载文件”;另存为;

Asp.net 使用“下载文件”;另存为;,asp.net,vb.net,save-as,downloadfile,Asp.net,Vb.net,Save As,Downloadfile,我需要编写一个进程,在我的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") 是否有一种内置的方法,可以通过“另存为”

我需要编写一个进程,在我的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
请尝试下面的代码

Response.ContentType = "report/rpt";

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

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

Response.End();

虽然我意识到这不是你问题的答案(见对托马斯答案的评论),但有时保持简单是一个好办法

Please right-click this link and save the file
<a href=""http://archive.ncsa.illinois.edu/primer.html">HTML Primer</a>
请右键单击此链接并保存文件

看不出这在任何方面有什么帮助。Crystal reports在任何地方都没有提到……它只是一个例子。这里我们可以使用html或jpeg。它可以是任何东西。这不是吗?+1,因为这是一个有效的答案。您可以使用TransmitFile通过SaveAs提供此代码所需的文件。非常感谢。(欢迎使用Stackoverflow!)这是正确的,但要注意不同的浏览器对非ascii字符或空格使用不同的编码。这只是一个例子。这里我们可以使用html或jpeg。它可以是任何东西。不是吗?