473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Determine file size before download (HttpWebRequest & HttpWebResponse)

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
15 6361
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
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
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
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
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
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
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
"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
"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
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
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
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
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
"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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mark Rae | last post by:
Hi, Can anyone please tell me if it's possible to use HttpWebRequest and HttpWebResponse in a class in a Windows application? I've tried referencing System and System.Web but there's still...
16
by: Cheung, Jeffrey Jing-Yen | last post by:
I have a windows form application that generates a request, downloads an image, and waits the user to enter in login info. Unfortunately, this image is dynamic and based on session data. I have...
0
by: Aryan | last post by:
Hi, I am new to HttpWebRequest and HttpWebResponse object, so please help me out for this problem. I am having application which is in ASP.NET. This ASP.NET application talks with ASP and then...
0
by: S N | last post by:
I am using the following code to hide the download url of files on my website. The code uses Response.Binarywrite to send file to the client. Kindly indicate the maximum size of the file that can be...
14
by: S N | last post by:
I am using the following code to hide the download url of files on my website. The code uses Response.Binarywrite to send file to the client. Kindly indicate the maximum size of the file that can be...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.