473,491 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Determining the size of a file via a URL

Hello,

I'd like to determine the size of a file via a URL. I'm not even sure how
to do this on the local machine, let alone a URL. Any help would be greatly
appreciated.

Thanks!
Nov 21 '05 #1
3 1358
there is a content-length field in the response header. I added a line
to a program that does something else to give you a rough example --
the inserted line is just above the Catch statement. (the code in this
sample is pretty rough -- I was trying to figure out how to extract a
table of links from a site without having to visit it manually --
eventually it will work into a tool that can simulate an rss feed from
a page that doesn't have one...)

***
Module Module1

Sub Main(ByVal args() As String)

Dim url As String
If args.Length <> 0 Then
url = args(0)
Else
url = "http://code.box.sk/forum.php?did=multGeneral%20Coding"
End If

Dim sr As IO.StreamReader

Try
sr = New
IO.StreamReader(Net.WebRequest.Create(url).GetResp onse().GetResponseStream())
Console.WriteLine("Content-length: " &
Net.WebRequest.Create(url).GetResponse().ContentLe ngth.ToString())
Catch ex As Exception
Exit Sub
End Try

Dim response As String = sr.ReadToEnd()

Dim re As Text.RegularExpressions.Regex = New
Text.RegularExpressions.Regex("<a href=\""(.*?)\"">(.*?)</a>",
Text.RegularExpressions.RegexOptions.IgnoreCase)
Dim rehref As Text.RegularExpressions.Regex = New
Text.RegularExpressions.Regex("href=""(.*?)""",
Text.RegularExpressions.RegexOptions.IgnoreCase)
Dim reinnertext As Text.RegularExpressions.Regex = New
Text.RegularExpressions.Regex(">(.*?)<",
Text.RegularExpressions.RegexOptions.IgnoreCase)
Dim mc As Text.RegularExpressions.MatchCollection =
re.Matches(response)

Dim m As Text.RegularExpressions.Match

Dim mhref As Text.RegularExpressions.Match
Dim minnertext As Text.RegularExpressions.Match

Dim strhref As String
Dim strinnertext As String

For Each m In mc
'Console.WriteLine(m.ToString())
Try
mhref = rehref.Match(m.ToString())
strhref = mhref.ToString()
strhref = strhref.Substring(6, strhref.Length - 7)
minnertext = reinnertext.Match(m.ToString())
strinnertext = minnertext.ToString()
strinnertext = strinnertext.Substring(1, strinnertext.Length - 2)
Console.WriteLine(strinnertext.PadRight(40) & ControlChars.Tab &
strhref)
Catch ex As Exception
Throw (ex)
End Try
Next
End Sub

End Module

Nov 21 '05 #2
Thank you!

"stand__sure" <st*********@hotmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
there is a content-length field in the response header. I added a line
to a program that does something else to give you a rough example --
the inserted line is just above the Catch statement. (the code in this
sample is pretty rough -- I was trying to figure out how to extract a
table of links from a site without having to visit it manually --
eventually it will work into a tool that can simulate an rss feed from
a page that doesn't have one...)

***
Module Module1

Sub Main(ByVal args() As String)

Dim url As String
If args.Length <> 0 Then
url = args(0)
Else
url = "http://code.box.sk/forum.php?did=multGeneral%20Coding"
End If

Dim sr As IO.StreamReader

Try
sr = New
IO.StreamReader(Net.WebRequest.Create(url).GetResp onse().GetResponseStream())
Console.WriteLine("Content-length: " &
Net.WebRequest.Create(url).GetResponse().ContentLe ngth.ToString())
Catch ex As Exception
Exit Sub
End Try

Dim response As String = sr.ReadToEnd()

Dim re As Text.RegularExpressions.Regex = New
Text.RegularExpressions.Regex("<a href=\""(.*?)\"">(.*?)</a>",
Text.RegularExpressions.RegexOptions.IgnoreCase)
Dim rehref As Text.RegularExpressions.Regex = New
Text.RegularExpressions.Regex("href=""(.*?)""",
Text.RegularExpressions.RegexOptions.IgnoreCase)
Dim reinnertext As Text.RegularExpressions.Regex = New
Text.RegularExpressions.Regex(">(.*?)<",
Text.RegularExpressions.RegexOptions.IgnoreCase)
Dim mc As Text.RegularExpressions.MatchCollection =
re.Matches(response)

Dim m As Text.RegularExpressions.Match

Dim mhref As Text.RegularExpressions.Match
Dim minnertext As Text.RegularExpressions.Match

Dim strhref As String
Dim strinnertext As String

For Each m In mc
'Console.WriteLine(m.ToString())
Try
mhref = rehref.Match(m.ToString())
strhref = mhref.ToString()
strhref = strhref.Substring(6, strhref.Length - 7)
minnertext = reinnertext.Match(m.ToString())
strinnertext = minnertext.ToString()
strinnertext = strinnertext.Substring(1, strinnertext.Length - 2)
Console.WriteLine(strinnertext.PadRight(40) & ControlChars.Tab &
strhref)
Catch ex As Exception
Throw (ex)
End Try
Next
End Sub

End Module

Nov 21 '05 #3
you're welcome

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5406
by: Luca | last post by:
I have the following problem: I'm developing a system where there are some processes that communicate each other via message queues; the message one process can send to another process is as...
2
2226
by: Phil Galey | last post by:
In VB.NET I find the IO object very handy in replacing most of the functionality of the FileSystemObject. One exception, however, is in determining the size of a file. How can you determine the...
12
7850
by: Raja | last post by:
How to know the buffer size and increase buffer size in c++.
2
7873
by: Phil Galey | last post by:
Using the following, you can determine the size of a file: Dim fi As New IO.FileInfo(<Path to file>) MsgBox(fi.Length) .... but what about the size of a directory? The IO.DirectoryInfo object...
14
2725
by: googler | last post by:
Is there any C library function that returns the size of a given file? Otherwise, is there a way in which file size can be determined in a C program? I need to get this for both Linux and Windows...
2
1542
by: Doug | last post by:
Hi, It looks like the only way to get a size of a file within dot net is to use FileInfo and the Length property. However that only returns the number of bytes in the file which is translating...
9
3829
by: vineeth | last post by:
Hello all, I have come across a weird problem, I need to determine the amount of bytes read from a file, but couldn't figure it out , My program does this : __ file = open("somefile") data =...
13
10558
by: writeson | last post by:
Hi all, I'm writing some code that monitors a directory for the appearance of files from a workflow. When those files appear I write a command file to a device that tells the device how to...
0
177
by: Cameron Simpson | last post by:
On 10Jul2008 13:20, Manuel Vazquez Acosta <mva.led@gmail.comwrote: | Cameron Simpson wrote: | On 09Jul2008 15:54, Ethan Furman <ethan@stoneleaf.uswrote: | >The solution my team has used is to...
38
8929
Frinavale
by: Frinavale | last post by:
I'm implementing a Silverlight application that uses Sockets to receive data that is pushed to it from a Socket Server. (Silverlight only supports the TCP protocol) The Socket Server pushes a...
0
7115
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
7154
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
7190
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
7360
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...
1
4881
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4578
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3086
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1392
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.