Use WebClient to download information into a file : WebClient : Network C# Examples


C# Examples » Network » WebClient »

 

Use WebClient to download information into a file









    
using  System;  
using  System.Net;  
using  System.IO;  
  
class  MainClass  {    
    public  static  void  Main()  {  
        WebClient  user  =  new  WebClient();  
        string  uri  =  "http://www.navioo.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.");  
    }  
}
    
   
  
   



Output

Downloading data from http://www.navioo.com to data.txt
Download complete.


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Network
» WebClient