Programmatically download file form web using C#

/// <summary>

/// This method downloads a file form internet url.

/// </summary>

void DownloadDotNetFramework()

{

    string OutPutpath = @”C:\DownlodedRtf.rtf”;

    WebClient oWebClient = new WebClient();

    string url = @”http://dl.dropbox.com/u/5969904/How%20to%20use%20the%20Public%20folder.rtf&#8221;;

    //Add callback function which will call after download complete.

    oWebClient.DownloadFileCompleted += new AsyncCompletedEventHandler(oWebClient_DownloadFileCompleted);

    oWebClient.DownloadFileAsync(new Uri(url), OutPutpath);

}

 

/// <summary>

/// Method which will call after completion of download.

/// </summary>

/// <param name=”sender”></param>

/// <param name=”e”></param>

void oWebClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)

{

    MessageBox.Show(“File downloaded.”);

}

Advertisements

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: