Click here to Skip to main content
13,253,159 members (50,496 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


14 bookmarked
Posted 30 May 2012

Download File Using C#

, 30 May 2012
Rate this:
Please Sign up or sign in to vote.
Download file using C#.


This article describes code to download a file using C#...


While browsing forums today I came across a question which asked for a solution to download a file from a web server programmatically. The solution is very simple and below is the code which achieves the goal. Here I am downloading a file asynchronously on Button Click.

Using the code

private void buttonDownloadFile_Click(object sender, EventArgs e)
    string url = @"";
    // Create an instance of WebClient
    WebClient client = new WebClient();
    // Hookup DownloadFileCompleted Event
    client.DownloadFileCompleted +=    new AsyncCompletedEventHandler(client_DownloadFileCompleted);

    // Start the download and copy the file to c:\temp
    client.DownloadFileAsync(new Uri(url), @"c:\temp\image35.png");

void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
    MessageBox.Show("File downloaded");

You can also download the file synchronously using WebClient.DownloadFile() method.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

You may also be interested in...


Comments and Discussions

QuestionDownload files from HTTPS Pin
MohamedImtiyaz.net10-Feb-15 4:25
memberMohamedImtiyaz.net10-Feb-15 4:25 
NewsDownload file from secure folder Pin
jayprakashjaysun2-Dec-14 2:17
memberjayprakashjaysun2-Dec-14 2:17 
GeneralMy vote of 1 Pin
Member 1079524529-Sep-14 3:54
memberMember 1079524529-Sep-14 3:54 
Questionregarding youtube Pin
aman bhardwaj9-Sep-14 22:51
memberaman bhardwaj9-Sep-14 22:51 
GeneralMy vote of 5 Pin
Chan Nyein12-Apr-14 17:54
memberChan Nyein12-Apr-14 17:54 
QuestionLike it Pin
Siva Hyderabad27-Feb-14 19:17
memberSiva Hyderabad27-Feb-14 19:17 
Questionhello Pin
Rahim Lotfi19-Feb-14 11:14
memberRahim Lotfi19-Feb-14 11:14 
QuestionDownload multiple files to a folder from a url Pin
mehrarohit12-Feb-14 19:20
membermehrarohit12-Feb-14 19:20 
GeneralMy vote of 4 Pin
ali yeganeh31-Oct-12 10:51
memberali yeganeh31-Oct-12 10:51 
GeneralRe: My vote of 4 Pin
Member 93199625-Feb-13 7:44
memberMember 93199625-Feb-13 7:44 
GeneralMy vote of 4 Pin
kishore doni28-Aug-12 1:57
memberkishore doni28-Aug-12 1:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171114.1 | Last Updated 30 May 2012
Article Copyright 2012 by tejasbhalani
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid