Async. Download progress bar c#
The code for creating an async. download progress bar , allows user to track how much data is downloaded
WebClient client = new WebClient();
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
//// Starts the download
string folder_path =”Location to save file”;
client.DownloadFileAsync(new Uri(downloadUrl), folder_path,””);
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
double bytesIn = double.Parse(e.BytesReceived.ToString());
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
double percentage = bytesIn / totalBytes * 100;
downloadProgress.Text = int.Parse(Math.Truncate(percentage).ToString()).ToString()+” % finished”;
}