This snippet downloads a file using the WebClient Class from a website.
using System;
using System.Net;
class Program
{
static void Main(string[] args)
{
string host ="http://www.yourdomain.com/file.zip";
string savelocation = Environment.CurrentDirectory + "\\" + host.Substring(host.LastIndexOf("/") + 1);
try
{
WebClient wClient = new WebClient();
wClient.DownloadFile(host, savelocation);
Console.WriteLine("File has been downloaded to " + savelocation);
}
catch (WebException e)
{
Console.WriteLine(e.Message);
}
Console.ReadKey();
}
}
No comments:
Post a Comment