Created
April 6, 2023 12:36
-
-
Save bassuny3003/2c1cef498ee49a99460bc5e55c3871a2 to your computer and use it in GitHub Desktop.
Download File Using C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void DownloadFile(string urlAddress, string location) | |
{ | |
using (WebClient client = new WebClient()) | |
{ | |
Uri uri = new Uri(urlAddress); | |
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged); | |
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted); | |
client.DownloadFileAsync(uri, location); | |
} | |
} | |
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) | |
{ | |
DownloadProgbar.Value = e.ProgressPercentage; | |
} | |
void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) | |
{ | |
if (e.Cancelled == true) | |
{ | |
MessageBox.Show("Download has been canceled."); | |
} | |
else | |
{ | |
MessageBox.Show("Download completed!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment