8

I am using this method (WebClient Class) for downloading a file from the Internet :

private Task DownloadUpdate(string url, string fileName)
{
       var wc = new WebClient();
       return wc.DownloadFileTaskAsync(new Uri(url), @"c:\download" + fileName);
}

How can I make the download resumable using the above code?

A-Sharabiani
  • 17,750
  • 17
  • 113
  • 128
Sirwan Afifi
  • 10,654
  • 14
  • 63
  • 110
  • See the Range headers (related: http://stackoverflow.com/questions/1434647/using-the-http-range-header-with-a-range-specifier-other-than-bytes). I'm not sure if WebClient has any standard support for dealing with Range (or the response Content-Range) headers which are required for HTTP downloading resuming - in which case, seek a different library/wrapper :D – user2246674 Jul 22 '13 at 20:54
  • 2
    Here is another overview http://stackoverflow.com/questions/1336203/httpwebrequest-or-webrequest-resume-download-asp-net (I guess WebClient does support basic range wrapping; but you'll still be required to correctly send and handle the range data) and even more of an implementation http://stackoverflow.com/questions/16270216/download-large-file-from-http-with-resume-retry-support-in-net .. its amazing what a little searching can do (found via "C# web client resume download"). – user2246674 Jul 22 '13 at 20:56

1 Answers1

6

From HttpWebRequest or WebRequest - Resume Download ASP.NET:

Resuming files is done by specifying the byte range of the file you would like to download using the Range HTTP header. This can be done in .NET with the HttpWebRequest.AddRange function.

For example:

request.AddRange(1000); 
Community
  • 1
  • 1
Sirwan Afifi
  • 10,654
  • 14
  • 63
  • 110