For a web application I’m currently working on, I want to download a file from internet to my web server.
I can use below code to download the file to the web server’s hard drive, what should I set to the destination path to get this working. We are planing to host this site in a shared hosting environment.
using System.Net;
using(var client = new WebClient())
{
client.DownloadFile("http://file.com/file.txt", @"C:\file.txt");
}
I think common way to do it is this:
or
Also notice, that WebClient class implements IDisposable, so you should use dispose or using struct.
And I eager you to read some naming convention for c# (local variables usually start with lower case letter).