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

Determining the size of a file via a URL

P: n/a
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
Share this Question
Share on Google+
3 Replies


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

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

P: n/a
you're welcome

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.