Asynchronous downloading in C# [modified]
-
In C#, is there a simple way to resume an download over http, transparantly? For example, i call a function to download a file x to drive c:. In the middle of the operation, I close the downloading program. The program would abort the transfer, but not delete the partially downladed file x. I start the program, and once again call the function to download the same file x to driver c:. The function would realize that there is already a part of file x present on drive c: and then resume the download. Can any one help me??? Thanking U, Sunil G.
modified on Saturday, May 1, 2010 4:38 AM
-
In C#, is there a simple way to resume an download over http, transparantly? For example, i call a function to download a file x to drive c:. In the middle of the operation, I close the downloading program. The program would abort the transfer, but not delete the partially downladed file x. I start the program, and once again call the function to download the same file x to driver c:. The function would realize that there is already a part of file x present on drive c: and then resume the download. Can any one help me??? Thanking U, Sunil G.
modified on Saturday, May 1, 2010 4:38 AM
-
In C#, is there a simple way to resume an download over http, transparantly? For example, i call a function to download a file x to drive c:. In the middle of the operation, I close the downloading program. The program would abort the transfer, but not delete the partially downladed file x. I start the program, and once again call the function to download the same file x to driver c:. The function would realize that there is already a part of file x present on drive c: and then resume the download. Can any one help me??? Thanking U, Sunil G.
modified on Saturday, May 1, 2010 4:38 AM
Using WebClient you can download your file synchronously as well as asynchronously. Download File Synchronously
using System.Net;
WebClient webClient = new WebClient();
webClient.DownloadFile("http://mysite.com/myfile.txt", @"c:\myfile.txt");Download File Asynchronously
private void btnDownload_Click(object sender, EventArgs e)
{
WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
webClient.DownloadFileAsync(new Uri("http://mysite.com/myfile.txt"), @"c:\myfile.txt");
}private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar.Value = e.ProgressPercentage;
}private void Completed(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("Download completed!");
}Hope this will help!
Jinal Desai - LIVE
-
Using WebClient you can download your file synchronously as well as asynchronously. Download File Synchronously
using System.Net;
WebClient webClient = new WebClient();
webClient.DownloadFile("http://mysite.com/myfile.txt", @"c:\myfile.txt");Download File Asynchronously
private void btnDownload_Click(object sender, EventArgs e)
{
WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
webClient.DownloadFileAsync(new Uri("http://mysite.com/myfile.txt"), @"c:\myfile.txt");
}private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar.Value = e.ProgressPercentage;
}private void Completed(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("Download completed!");
}Hope this will help!
Jinal Desai - LIVE
Madam I think u didnt get my point. For example, I call a function to download a file x to drive c:. In the middle of the operation, I close the downloading program. The program would abort the transfer, but not delete the partially downladed file x. I start the program, and once again call the function to download the same file x to driver c:. The function would realize that there is already a part of file x present on drive c: and then resume the download. Thanking You, Sunil G.
-
In C#, is there a simple way to resume an download over http, transparantly? For example, i call a function to download a file x to drive c:. In the middle of the operation, I close the downloading program. The program would abort the transfer, but not delete the partially downladed file x. I start the program, and once again call the function to download the same file x to driver c:. The function would realize that there is already a part of file x present on drive c: and then resume the download. Can any one help me??? Thanking U, Sunil G.
modified on Saturday, May 1, 2010 4:38 AM
The
HttpWebRequest.
AddRange()
[^] method allows you to resume downloading from a specific point. /raviMy new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
Madam I think u didnt get my point. For example, I call a function to download a file x to drive c:. In the middle of the operation, I close the downloading program. The program would abort the transfer, but not delete the partially downladed file x. I start the program, and once again call the function to download the same file x to driver c:. The function would realize that there is already a part of file x present on drive c: and then resume the download. Thanking You, Sunil G.
-
In C#, is there a simple way to resume an download over http, transparantly? For example, i call a function to download a file x to drive c:. In the middle of the operation, I close the downloading program. The program would abort the transfer, but not delete the partially downladed file x. I start the program, and once again call the function to download the same file x to driver c:. The function would realize that there is already a part of file x present on drive c: and then resume the download. Can any one help me??? Thanking U, Sunil G.
modified on Saturday, May 1, 2010 4:38 AM
I would recommend using Socket Class which provides you to resume, stop your downloading or Uploading.
Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan