WebClient
string contents = new WebClient().DownloadString(url);
public static void DownloadFile(string remoteUrl, string localFile, bool ignoreErrors) { string errorDetail = ""; string tempFile = localFile + ".tmp"; try { errorDetail = "Couldn't delete downloaded file " + localFile; File.Delete(tempFile); } catch { } try { errorDetail = "Couldn't download file " + tempFile; if (DOWNLOAD_VIA_BROWSER) { WebBrowser browser = new WebBrowser(); browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler( browser_DocumentCompleted); browser.Navigate(remoteUrl); _browser_working = true; while (_browser_working) Application.DoEvents(); StreamReader reader = new StreamReader(browser.DocumentStream); string s = reader.ReadToEnd(); File.WriteAllText(tempFile, s); } else { new WebClient().DownloadFile(remoteUrl, tempFile); } File.Delete(localFile); File.Move(tempFile, localFile); } catch (Exception ex) { if (!ignoreErrors) { ExceptionHandler.Show(ex, errorDetail); throw ex; } } }
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.