Downloading File From HTTP

  • Thread starter Thread starter Mark
  • Start date Start date
Mark said:
Hello.

How can I download some file from HTTP (for example
"http://www.mysite.com/files/myfile.doc") and then save it to my
local drive (for example "C:\MyFiles\myfile.doc")?

Thank you.

That's easily done using System.Net.WebClient:

try
{
WebClient client = new WebClient();
client.DownloadFile(
"http://www.mysite.com/files/myfile.doc",
@"C:\MyFiles\myfile.doc");
}
catch (WebException ex)
{
// Handle error.
}

For more advanced HTTP operations, use System.Net.HttpWebRequest.

Cheers,
 
Back
Top