문제

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?

도움이 되었습니까?

해결책

You can use

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

다른 팁

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>

Try the below code

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