Its a single line code to download a file given a url and downlaod dir
(new WebClient()).DownloadFile(url, downlaoddir);
But if there is windows authentication required on the site the maybe three lines :)
WebClient client = new WebClient();
client.UseDefaultCredentials = true;
client.DownloadFile(url, downloaddir);
But it seems to a very easy option to work with.
It also provides multiple async downloads etc.
Ex:
WebClient wc = new WebClient();
string website1 = "http://remote1.ispnet.net";
string website2 = "http://remote2.ispnet.net";
string website3 = "http://remote3.ispnet.net/login";
NetworkCredential nc1 = new NetworkCredential("mike", "guitars");
NetworkCredential nc2 = new NetworkCredential("evonne", "singing", "home");
NetworkCredential nc3 = new NetworkCredential("alex", "drums");
CredentialCache cc = new CredentialCache();
cc.Add(new Uri(website1), "Basic", nc1);
cc.Add(new Uri(website2), "Basic", nc2);
cc.Add(new Uri(website3), "Digest", nc3);
wc.Credentials = cc;
wc.DownloadFile(website1, "website1.htm");
wc.DownloadFile(website2, "website2.htm");
wc.DownloadFile(website3, "website3.htm");
form - Example Reference
Friday, October 10, 2008
Read/Modify Application Configuration .config file
Read
string value = ConfigurationManager.AppSettings["oldPlace"];
Write
System.Configuration.Configuration config =ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["oldPlace"].Value = "3";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
string value = ConfigurationManager.AppSettings["oldPlace"];
Write
System.Configuration.Configuration config =ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["oldPlace"].Value = "3";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
Subscribe to:
Posts (Atom)