Tutorial :Calculate the total size of all files to download



Question:

VS 2008 SP1

I am creating a updater that my application will, when started will fetch updated files from a web server.

I am wonder how I can get the total size of the files to download?

I need this information as I am using a progress bar to monitor the amount that is currently downloading, and need to set the total as the max value of the progress bar.

Many thanks for any advice,


Solution:1

How does your updater work out which files to download? So long as you can get a list of files to download and their sizes before you start downloading anything, you've just got to sum the sizes...

The only problem I could see is if you download some files and then (after updating) find you need to download more.


Solution:2

To get the sum over a number of files, loop and sum; then the question becomes how to get the size of a single file without downloading it. Here, the "HEAD" verb may help. You mention WebClient; here is an example of subclassing WebClient to get just the headers.

Of course, it isn't guaranteed that you'll get a content-length header...


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »