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

Determine file size before download (HttpWebRequest & HttpWebResponse)

P: n/a
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)

---

Thx in advance

/Snedker
Nov 20 '05 #1
Share this Question
Share on Google+
15 Replies


P: n/a
Cor
Hi Snedker,

Have a look at the "headers" attribute from Httpwebresponse

I hope this helps,

Cor
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)

---

Thx in advance

/Snedker

Nov 20 '05 #2

P: n/a
On Tue, 13 Jan 2004 09:27:56 +0100, "Cor" <no*@non.com> wrote:

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
Hi Snedker,

Have a look at the "headers" attribute from Httpwebresponse

I hope this helps,

Cor


Nov 20 '05 #3

P: n/a
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
///
Nov 20 '05 #4

P: n/a
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 ???
Nov 20 '05 #5

P: n/a
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 ???
Nov 20 '05 #6

P: n/a
Hi Derry,

Show us some code, this looks like a normal coding error?

Cor
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 ???

Nov 20 '05 #7

P: n/a
Hi Derry,

Show us some code, this looks like a normal coding error?

Cor
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 ???

Nov 20 '05 #8

P: n/a
"Cor Ligthert" <no**********@planet.nl> schrieb

Show us some code, this looks like a normal coding error?


Yes, and it looks like VB6. :)
--
Armin

Nov 20 '05 #9

P: n/a
"Cor Ligthert" <no**********@planet.nl> schrieb

Show us some code, this looks like a normal coding error?


Yes, and it looks like VB6. :)
--
Armin

Nov 20 '05 #10

P: n/a
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 ???
Nov 20 '05 #11

P: n/a
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 ???
Nov 20 '05 #12

P: n/a
Hi Derry,

Show us some code, this looks like a normal coding error?

Cor
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 ???

Nov 20 '05 #13

P: n/a
Hi Derry,

Show us some code, this looks like a normal coding error?

Cor
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 ???

Nov 20 '05 #14

P: n/a
"Cor Ligthert" <no**********@planet.nl> schrieb

Show us some code, this looks like a normal coding error?


Yes, and it looks like VB6. :)
--
Armin

Nov 20 '05 #15

P: n/a
"Cor Ligthert" <no**********@planet.nl> schrieb

Show us some code, this looks like a normal coding error?


Yes, and it looks like VB6. :)
--
Armin

Nov 20 '05 #16

This discussion thread is closed

Replies have been disabled for this discussion.