Downloading files in pieces with WebRequest/WebResponse

  • Thread starter Thread starter Richard K Bethell
  • Start date Start date
R

Richard K Bethell

From what I am reading, a System.Net.WebRequest can be set to retrieve just
parts of a file in the WebResponse, using the .AddRange method to specify a
byte range. This would be very useful for me for a client that I want to
build which will download files in a small footprint.

However, what I'm missing (probably just overlooking) is how to use the
WebRequest or WebResponse to query a file's size, so that you know what your
maximum range is - how can you get the number of bytes for a potential
download before actually beginning?

Richard
 
However, what I'm missing (probably just overlooking) is how to use the
WebRequest or WebResponse to query a file's size, so that you know what
your maximum range is - how can you get the number of bytes for a
potential download before actually beginning?

AFAIK there is no simple way to knowing it. Some web servers will specify
content-length, and some will not. they can even put content-length to -1.

So, what the client has to do in this case?

In your situation, I'd specified some fixed range which can be adjusted by
some heuristics, if content length is not specified.
 
Back
Top