downloadFile with “save as”

不羁岁月 提交于 2020-01-04 02:54:39

问题


I need to write a process to download an html file locally in my vb.net web app. I am currently using webClient.DownloadFile :

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

Is there a built-in way to do this with a "save as" window instead, so that the user can select the location they would like the file to be saved to? Or would I need to write my own?


回答1:


You can use

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



回答2:


Whilst I realise this isn't an answer to your question (see comment on Thomas' answer), sometimes keeping it simple is a good way to go

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



回答3:


Try the below code

Response.ContentType = "report/rpt";

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

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

Response.End();


来源:https://stackoverflow.com/questions/5990377/downloadfile-with-save-as

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!