Determine file size before download (HttpWebRequest & HttpWebResponse)

S

Snedker

I'm using (HttpWebRequest and HttpWebResponse to check for updates.
But how do I determine the size of the file before download?

What I have in mind is a status text like

"You have downloaded xxxx of yyyy bytes"

I'm trying to find the y's within this:

---

Dim wr As HttpWebRequest =
CType(HttpWebRequest.Create("http://dbconsult.dk/test/sm.zip"),
HttpWebRequest)
Dim ws As HttpWebResponse = CType(wr.GetResponse(),
HttpWebResponse)

Dim str As Stream = ws.GetResponseStream()
Dim inBuf(10000000) As Byte

Dim bytesToRead As Integer = CInt(inBuf.Length)
 
C

Cor

Hi Snedker,

Have a look at the "headers" attribute from Httpwebresponse

I hope this helps,

Cor
 
S

Snedker

Hi Cor,

Yes, it most certainly did! :)

If I may pop another question: my Header returns something like:

"Server: Microsoft-IIS/5.0
Date: Tue, 13 Jan 2004 21:38:55 GMT
Content-Type: video/mpeg
Accept-Ranges: bytes
Last-Modified: Wed, 24 Sep 2003 09:56:34 GMT
ETag: "80225a238282c31:9aa"
Content-Length: 1435652"

Is it possible to refer to each of these individually? I've tried
looking through the properties of the Headers part, but can't seem to
find what I'm looking for...

Once again: Thx ! :)

/Snedker
 
C

Cor

Hi Snedker,

You can try this (I changed some things to make it more general)

I hope this helps?

Cor

\\\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
///
 
G

Guest

How could I stop this" Object Variable or with block variable not set" Run - Time error ' 91 ' ,.
Is there a software up date for this ???
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top