Thursday, July 29, 2010

Accessing files on internet Internet—Downloading Files

 Accessing files on internet Internet—Downloading Files


Downloading Files


Two methods are available for downloading a file using WebClient. The method you choose depends on how you want to process the file's contents. If you simply want to save the file to disk, then you use the DownloadFile() method. This method takes two parameters: the URI of the file and a location (path and file name) to save the requested data:


WebClient Client = new WebClient();
Client.DownloadFile("http://www.reuters.com/", "ReutersHomepage.htm");

More commonly, your application will want to process the data retrieved from the Web site. To do this, you use the OpenRead() method, which returns a Stream reference that you can then use to retrieve the data into memory:


WebClient Client = new WebClient();
Stream strm = Client.OpenRead("http://www.reuters.com/");

No comments:

Post a Comment