By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,986 Members | 1,193 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,986 IT Pros & Developers. It's quick & easy.

Filesize using WebClient

P: n/a
Howto get the filesize from a file on "the web" using the 2005
WebClient?

TIA,
Leon
Mar 29 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hello, Leon!

LF> Howto get the filesize from a file on "the web" using the 2005
LF> WebClient?

One of the ways will be watching for Content-Length header in ResponseHeaders. But servers often do not set this header.

That is why you cannot obtain valid file size a priori. Web Servers pass contents of the file in the stream-like manner. So you have to receive until server closes connection.

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Mar 29 '06 #2

P: n/a
On Wed, 29 Mar 2006 15:09:27 +0300, "Vadym Stetsyak" <va*****@ukr.net>
wrote:
Hello, Leon!

LF> Howto get the filesize from a file on "the web" using the 2005
LF> WebClient?

One of the ways will be watching for Content-Length header in ResponseHeaders. But servers often do not set this header.

That is why you cannot obtain valid file size a priori. Web Servers pass contents of the file in the stream-like manner.
So you have to receive until server closes connection.


Hello Vadym!

Thanks for the answer! The problem is: I only need the last 128 bytes
of the file and (to save time- as well as bandwidth) I wished I did
not have to download the entire stream. Then again, after some
testing: the stream returned by "OpenRead" method does not support
seek operations anyway... Again: thanks for the answer anyway!

Leon
Mar 29 '06 #3

P: n/a
LF> Thanks for the answer! The problem is: I only need the last 128 bytes
LF> of the file and (to save time- as well as bandwidth) I wished I did
LF> not have to download the entire stream. Then again, after some
LF> testing: the stream returned by "OpenRead" method does not support
LF> seek operations anyway... Again: thanks for the answer anyway!

Then you can use Range header. Use WebClient.Headers property to add headers

Something like this

WebClient myWebClient = new WebClient();
myWebClient.Headers.Add("Range","bytes=-128");

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Mar 29 '06 #4

P: n/a
On Wed, 29 Mar 2006 16:55:22 +0300, "Vadym Stetsyak" <va*****@ukr.net>
wrote:
LF> Thanks for the answer! The problem is: I only need the last 128 bytes
LF> of the file and (to save time- as well as bandwidth) I wished I did
LF> not have to download the entire stream. Then again, after some
LF> testing: the stream returned by "OpenRead" method does not support
LF> seek operations anyway... Again: thanks for the answer anyway!

Then you can use Range header. Use WebClient.Headers property to add headers

Something like this

WebClient myWebClient = new WebClient();
myWebClient.Headers.Add("Range","bytes=-128");


Interesting.. I'll look into it!

Leon
Mar 30 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.