I know a method which is termed as Asynchronous method to download a file from web in Csharp. This method is useful to not block the main thread while is file is being downloaded. With help of event handlers the programmer can also indicate the download file's progress and whether it has completed download or not. The Asynchronous method to download a file is as follows:
Code:
private void btnDownload_Click(object sender, EventArgs EA)
{
WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
webClient.DownloadFileAsync(new Uri("http://siteeg.com/fileeg.txt"), @"D:\fileeg.txt");
}
private void ProgressChanged(object sender, DownloadProgressChangedEventArgs P)
{
progressBar.Value = P.ProgressPercentage;
}
private void Completed(object sender, AsyncCompletedEventArgs Ace)
{
MessageBox.Show("Finished downloading file");
}
Bookmarks