WebClient.DownloadFile : WebClient « System.Net « C# / C Sharp by API






WebClient.DownloadFile

 
using System; 
using System.Net; 
using System.IO; 
 
public class WebClientDemo {  
  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); 
    } catch (UriFormatException exc) { 
      Console.WriteLine(exc); 
    } 
      
    Console.WriteLine("Download complete."); 
  } 
}

   
  








Related examples in the same category

1.WebClient.BaseAddress
2.WebClient.Credentials
3.WebClient.DownloadData
4.WebClient.DownloadString(Uri u)
5.WebClient.Headers
6.WebClient.OpenRead(String url)
7.WebClient.OpenWrite
8.WebClient.ResponseHeaders
9.WebClient.UploadData
10.WebClient.UploadValues