I
I
IPv42016-06-30 22:11:22
Computer networks
IPv4, 2016-06-30 22:11:22

How to resume a file using WebClient?

The logic of this process seems to be clear to me:
We check the existence of the file. If it exists (let's omit the checks for the need to resume), then we take the file size and, when downloading, we substitute it in the "Range" header and we will download starting from the part where the download of the existing file ended.
The problem is that when loading even from the right byte, the file is overwritten.
I see a solution:
During the start of the download, check for the presence of a file, as was done earlier, and if there is, then from the desired byte, upload a new file there, but add the .bak extension . Thus, if the download is interrupted again, we can merge the existing file with the .bak file , after which we delete the latter and start resuming to the .bak file again .
But for me there was a problem - I don’t know how to glue the files correctly and how to subsequently display them in DownloadProgressChangedEventHandler so that when loading, the size is displayed not the number of bytes downloaded now (even from the desired fragment), but along with the second file with which they will be glued. Or if I start downloading from half, will 50% download progress be immediately displayed?
This time I would like to see code examples that will help me with the implementation, if not difficult.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rou1997, 2016-07-01
@Rou1997

By means of HttpWebRequest, you can immediately get the length (size) of the downloaded file, this is the Content-Length header, count it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question