getting size of file in bytes

  • Thread starter Thread starter Vikramaditya Singh
  • Start date Start date
V

Vikramaditya Singh

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
 
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...
 
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
 
Back
Top