Downloading Files using C#/VB.NET

Hi Everyone… Downloading any type of file using http request is not a big at all using either  C# or Visual Basic.NET code. Please follow the steps: 

1. You need to add an reference 

using System.Net;  2. Now you can use the class named as WebClient, so just declare an object of this class and intialize using 0 argumnet constructor. 

WebClinet myClient = new WebClient (); 

3.  Now you can use the method DownloadFile of WebClient class to start downloading the file. 

//myClient.DownloadFile (<Http Address>,<Local Path>)

string httpAddress = http://msdn2.microsoft.com/en-us/library/system.net.webclient.downloadfile(vs.71).aspx;

string localPath = “C:\myDownload”;

myClient.DownloadFile (httpAddress, localPath);

4. Thats it…change the httpAddress of your desired file and localPatth. 

Keep Smiling 🙂

Advertisements

One Response to “Downloading Files using C#/VB.NET”

  1. Omer Says:

    Nice bro its working perfectly…but what if i use the earlier versions i.e. .net framework 1.0 and 1.1 is there any change required???


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: