2

I have a text file with list of words and i have generated list of URLs with these word:

word1
word2
word3
.
.

http://www.example.com/word1
http://www.example.com/word2
http://www.example.com/word3

i see these code to run URLs, but these open browsers or media player ones:

  System.Diagnostics.Process.Start(URL);

or...

 WebBrowser1.Navigate(URL);

i want to run these URLs and save again files that are loaded with name "word1.mp3,word2.mp3,..." without opening browser or saving files one by one. how can i do that in windows form with c#?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
mortazavi
  • 401
  • 9
  • 22

2 Answers2

2

use System.net namespace and WebClient class to access internet pages from C#:

WebClient cl = new WebClient();
cl.DownloadFile(url, fileSaveAddress); //download the file

and the better way to download a file is using async methods:

    cl.DownloadFileAsync(URI, fileSaveAddress);

It will download the file asynchronously and will not hang the UI.

Shaharyar
  • 12,254
  • 4
  • 46
  • 66
  • Have a look at this question: http://stackoverflow.com/questions/4877741/access-to-the-path-is-denied it'll help you – Shaharyar Dec 31 '13 at 12:03
1

Following code snippet save HTML string of the specified URL without opening it. Alter it according to your scenario(client.DownloadFile).

    WebClient client = new WebClient(); 
    string content = client.DownloadString("http://www.google.com");
SMK
  • 2,098
  • 2
  • 13
  • 21