Use WebClient to download information into a file : WebClient « Network « C# / CSharp Tutorial






using System; 
using System.Net; 
using System.IO; 
 
class MainClass {  
  public static void Main() { 
    WebClient user = new WebClient(); 
    string uri = "http://www.java2s.com"; 
    string fname = "data.txt"; 
     
    try { 
      Console.WriteLine("Downloading data from " + uri + " to " + fname); 
      user.DownloadFile(uri, fname); 
    } catch (WebException exc) { 
      Console.WriteLine(exc); 
    } 
 
    Console.WriteLine("Download complete."); 
  } 
}
Downloading data from http://www.java2s.com to data.txt
Download complete.








33.18.WebClient
33.18.1.Use WebClient to download information into a file
33.18.2.Use WebClient to read website
33.18.3.Download string from a website using the WebClient
33.18.4.Download HTM files
33.18.5.Download File
33.18.6.Download Data
33.18.7.Upload Data
33.18.8.Open/Write Test
33.18.9.Web login
33.18.10.Open/Read Test
33.18.11.Response Headers
33.18.12.Upload Values
33.18.13.Set download string for WebClient