3

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?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Urbycoz
  • 7,247
  • 20
  • 70
  • 108

3 Answers3

5

You can use

Response.AddHeader("Content-Disposition", "attachment;filename=testfile_file.html");
Response.Write or Response.WriteFile
  • This is true but be aware different browsers use different encodings for non ascii chars or space – MJB May 13 '11 at 20:54
1

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>
Justin Wignall
  • 3,490
  • 20
  • 23
  • It was merely for an example. here we can use html or jpeg. It can be anything. Isn't that ? – Pankaj May 13 '11 at 10:37
0

Try the below code

Response.ContentType = "report/rpt";

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

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

Response.End();
Pankaj
  • 9,749
  • 32
  • 139
  • 283
  • Don't see how this helps in any way that hasn't already been provided. Crystal reports aren't mentioned anywhere... – Justin Wignall May 13 '11 at 10:25
  • It was merely for an example. here we can use html or jpeg. It can be anything. Isn't that ? – Pankaj May 13 '11 at 10:26
  • +1 as this is a valid answer. You can use TransmitFile to provide the provide the file trough SaveAs with this code. – TheBoyan Mar 05 '12 at 21:10