Mega Code Archive

 
Categories / C# Tutorial / Network
 

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.rntsoft.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.rntsoft.com to data.txt Download complete.