Determining the size of a file via a URL

  • Thread starter Thread starter Jozef
  • Start date Start date
J

Jozef

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!
 
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 Coding"
End If

Dim sr As IO.StreamReader

Try
sr = New
IO.StreamReader(Net.WebRequest.Create(url).GetResponse().GetResponseStream())
Console.WriteLine("Content-length: " &
Net.WebRequest.Create(url).GetResponse().ContentLength.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
 

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

Back
Top