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

getting size of file in bytes

P: n/a
i want to download a file using HttpWebResponse object from a web server.
But before starting download i want to find out total size of that file in
bytes. How can i do that.

Vikram
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 2004-01-27, Vikramaditya Singh <vi*********@rediffmail.com> wrote:
i want to download a file using HttpWebResponse object from a web server.
But before starting download i want to find out total size of that file in
bytes. How can i do that.

Vikram


When you request a file from the server it should set the Content-length
header - which contains the file size in bytes. This should be
reflected in the HttpWebResponse.ContentLength property...

--
Tom Shelton [MVP]
Nov 20 '05 #2

P: n/a
* "Vikramaditya Singh" <vi*********@rediffmail.com> scripsit:
i want to download a file using HttpWebResponse object from a web server.
But before starting download i want to find out total size of that file in
bytes. How can i do that.


<http://www.codeproject.com/csharp/WebDownload.asp>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3

P: n/a
Cor
Hi Vikramdithya,

I do not know if that information you got from Tom Shelton is better, but
now I saw you got a link from the *C#* man Herfried.K. Wagner,

Here is some VB code that does it for you.

\\\not tested as is
dim conlength as string
Dim wbRq As HttpWebRequest = DirectCast(WebRequest.Create(item.Text),
HttpWebRequest)
wbRq.Timeout = 2000
Try
Dim wbRs As HttpWebResponse = DirectCast(wbRq.GetResponse(),
HttpWebResponse)
Dim wbHCol As WebHeaderCollection = wbRs.Headers
For i As Integer = 0 To wbHCol.Count - 1
Dim header As String = wbHCol.GetKey(i)
Dim values As String() = wbHCol.GetValues(header)
If values.Length > 0 andalso header.Tolower = "content-lenght" Then
conlenght = values(0)
End If
Next
wbRs.Close()
Catch
conlength = "?"
End Try
///

I hope this helps a little bit?

Cor
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.