Documente Academic
Documente Profesional
Documente Cultură
articles
quick answers
jokercracker
discussions
community
help
Searchforarticles,questions,tips
CPOL
169.7K
13
Rate:
4.53 15 votes
Download file using C#.
Introduction
This article describes code to download a file using C#...
Background
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.
privatevoidbuttonDownloadFile_Click(objectsender,EventArgse)
{
stringurl=@"http://www.thereforesystems.com/wpcontent/uploads/2008/08/image35.png";
//CreateaninstanceofWebClient
WebClientclient=newWebClient();
//HookupDownloadFileCompletedEvent
client.DownloadFileCompleted+=newAsyncCompletedEventHandler(client_DownloadFileCompleted);
//Startthedownloadandcopythefiletoc:\temp
client.DownloadFileAsync(newUri(url),@"c:\temp\image35.png");
}
voidclient_DownloadFileCompleted(objectsender,AsyncCompletedEventArgse)
{
MessageBox.Show("Filedownloaded");
}
You can also download the file synchronously using WebClient.DownloadFile() method.
License
This article, along with any associated source code and files, is licensed under The Code Project Open License
CPOL
Share
EMAIL
Search Comments
Profile popupsSpacing Relaxed
Layout Normal
Go
Per page 25
Update
MohamedImtiyaz.net
jayprakashjaysun
My vote of 1
Member 10795245
29Sep14 18:54
regarding youtube
aman bhardwaj
10Sep14 13:51
My vote of 5
Chan Nyein
10Feb15 19:25
2Dec14 17:17
13Apr14 8:54
Like it
Siva Hyderabad
hello
Rahim Lotfi
20Feb14 2:14
mehrarohit
13Feb14 10:20
My vote of 4
ali yeganeh
1Nov12 1:51
Member 9319962
5Feb13 22:44
Re: My vote of 4
My vote of 4
kishore doni
News
28Feb14 10:17
Suggestion
Question
28Aug12 16:57
Refresh
Bug
Answer
Joke
Rant
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
Web01 | 2.8.1509020.2 | Last Updated 30 May 2012
Select Language
Layout: fixed |
fluid