PC Review


Reply
Thread Tools Rate Thread

Checking URL for file in VB.net how can it be done?

 
 
Daniel Padron
Guest
Posts: n/a
 
      1st Feb 2007
Ok. Maybe I shouldnt post such basic questions here in such an advanced
group but my high school programming teacher wont answer any questions
outside of his curriculum

My goal is create a program that will get feeded a url that links direcly
to a file [ex. http://www.example.com/video.avi] the program will then
determine if the file is there or not.

There are probably more efficient ways of doing what I want to do but this
is the way I have in mind:

1. dump the url's text into VB, in other words: what is actually in the
webpage. (Most likely since the file will not be there the string "File
could not be found" will be given to vb)

2. perform an [indexOf("File could not be found")] on the dumped text to
see if there if the file is acutually there.

3. if the indexOf gives a -1 that means that there was never a "file not
here" on the webpage therefore the file IS there!

Wow that was hard to explain. Please keep in mind that i'm in my first year
of programming in high school so please if you can explain in easier terms
is will be better for me to understand.

as a less important side question:
can vb DO things with websites? for example: can i write a program that
will actually fill out forms with correct data and submit them? what I have
in mind is writing programs that will send me an SMS when it is done doing
a task (using google send to phone:
http://toolbar.google.com/send/sms/index.php)
 
Reply With Quote
 
 
 
 
Bob O`Bob
Guest
Posts: n/a
 
      1st Feb 2007
Daniel Padron wrote:
> Ok. Maybe I shouldnt post such basic questions here in such an advanced
> group but my high school programming teacher wont answer any questions
> outside of his curriculum


the reason you should not post ""here"" is not that at all.

It is because of the two groups you have chosen, one of which does NOT cover dotnet.

Followups set to the dotnet group ONLY.



Bob
--
 
Reply With Quote
 
Karl E. Peterson
Guest
Posts: n/a
 
      1st Feb 2007
Daniel Padron <(E-Mail Removed)> wrote:
> Ok. Maybe I shouldnt post such basic questions here


Well, please note that VB.net and VB are *entirely* different languages, and each
have their own set of dedicated groups on this server. For the product you're
using, you'll find groups that contain ".dotnet." in their names to be most useful.

Good luck... Karl
--
..NET: It's About Trust!
http://vfred.mvps.org


 
Reply With Quote
 
Daniel Padron
Guest
Posts: n/a
 
      1st Feb 2007
> It is because of the two groups you have chosen, one of which does NOT
> cover dotnet.
>
> Followups set to the dotnet group ONLY.


fair enough. sorry.
 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      1st Feb 2007
Daniel,

Maybe will this help you, it is not an answer on your question, but the
parts are in it that you probably need.


http://www.vb-tips.com/dbpages.aspx?...f-56dbb63fdf1c

Cor

"Daniel Padron" <(E-Mail Removed)> schreef in bericht
news:Xns98C9CE5168820bioret@216.77.188.18...
> Ok. Maybe I shouldnt post such basic questions here in such an advanced
> group but my high school programming teacher wont answer any questions
> outside of his curriculum
>
> My goal is create a program that will get feeded a url that links direcly
> to a file [ex. http://www.example.com/video.avi] the program will then
> determine if the file is there or not.
>
> There are probably more efficient ways of doing what I want to do but this
> is the way I have in mind:
>
> 1. dump the url's text into VB, in other words: what is actually in the
> webpage. (Most likely since the file will not be there the string "File
> could not be found" will be given to vb)
>
> 2. perform an [indexOf("File could not be found")] on the dumped text to
> see if there if the file is acutually there.
>
> 3. if the indexOf gives a -1 that means that there was never a "file not
> here" on the webpage therefore the file IS there!
>
> Wow that was hard to explain. Please keep in mind that i'm in my first
> year
> of programming in high school so please if you can explain in easier terms
> is will be better for me to understand.
>
> as a less important side question:
> can vb DO things with websites? for example: can i write a program that
> will actually fill out forms with correct data and submit them? what I
> have
> in mind is writing programs that will send me an SMS when it is done doing
> a task (using google send to phone:
> http://toolbar.google.com/send/sms/index.php)



 
Reply With Quote
 
Branco Medeiros
Guest
Posts: n/a
 
      1st Feb 2007
Daniel Padron wrote:
<snip>
> My goal is create a program that will get feeded a url that links direcly
> to a file [ex.http://www.example.com/video.avi] the program will then
> determine if the file is there or not.

<snip>

It depends on what you really want with the "file" (not always the
link points really to the file. Sometimes the server performs some
processing before actually retrieving the "file", and may actually
return something completely different).

If you just want to check that the link is valid, then you may
consider using the System.Net.HttpRequest class:

<code>
'This must be at the file level:
Imports Net = System.Net
'...
'...
'...
'This would be in a method:
' Initializes the request
Dim Link As String = "http://www.example.com/video.avi"
Dim Req As Net.HttpWebRequest = _
CType(Net.WebRequest.Create(Link), Net.HttpWebRequest)
Req.Credentials = Net.CredentialCache.DefaultCredentials

'Prepares to probe the link
Dim Res As Net.HttpWebResponse = Nothing
Dim ValidLink As Boolean
Try
'Tries to get the an ok response from the server
Res = CType(Req.GetResponse(), Net.HttpWebResponse)
ValidLink = True
Catch Ex As Net.WebException
Finally
If Res IsNot Nothing Then Res.Close()
End Try
</code>

I guess you'll have no trouble following the code. What this code does
is to set a Boolean flag (ValidLink) if the link is valid or not. It
won't be valid if the server can't be located or if the server returns
an error code (which will be the case if the file is not there).

Now, if what you really want is to *download* the link's content, then
an easier solution would be to use the System.Net.WebClient class:

<code>
'Again, this must be at the file level:
Imports Net = System.Net
'...
'...
'...
'This would be in a method:
Dim Link As String = "http://www.example.com/video.avi"
Dim Target As String = "C:\video.avi"

Dim Downloaded As Boolean
Dim W As New Net.WebClient
Try
W.DownloadFile(Link, Target)
Downloaded = True
Catch Ex As Net.WebException
End Try
</code>

The code above will download the file returned by the specified link
and save its contents in the "C:\video.avi" file (a terrible choice of
location, I admit, but this is just an example. I believe you'd put
the download in a more apropriate folder). If the link is valid and
the file was downloaded, the "Downloaded" flag will be set to True.

HTH.

Regards,

Branco.

 
Reply With Quote
 
Daniel Padron
Guest
Posts: n/a
 
      1st Feb 2007
Thank you Branco.
That worked perfectly, now I just gotta get the easy parts done!
BTW, thank you also for the other one (to actually download) even though
i wont use it right now, I know i will need it later.

Thank you.


> <code>
> 'This must be at the file level:
> Imports Net = System.Net
> '...
> '...
> '...
> 'This would be in a method:
> ' Initializes the request
> Dim Link As String = "http://www.example.com/video.avi"
> Dim Req As Net.HttpWebRequest = _
> CType(Net.WebRequest.Create(Link), Net.HttpWebRequest)
> Req.Credentials = Net.CredentialCache.DefaultCredentials
>
> 'Prepares to probe the link
> Dim Res As Net.HttpWebResponse = Nothing
> Dim ValidLink As Boolean
> Try
> 'Tries to get the an ok response from the server
> Res = CType(Req.GetResponse(), Net.HttpWebResponse)
> ValidLink = True
> Catch Ex As Net.WebException
> Finally
> If Res IsNot Nothing Then Res.Close()
> End Try
> </code>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking a CSV file. Smith Microsoft C# .NET 6 17th Apr 2009 06:56 PM
Conflicting used space information when checking the drive property against marking all files and checking the marked file properties. elloko Windows XP Configuration 3 19th Dec 2004 05:34 AM
File checking BrettsNEWS Microsoft Access Forms 7 24th Apr 2004 05:08 AM
checking name of file clayton Microsoft Excel Worksheet Functions 2 5th Mar 2004 04:26 PM
File Checking Donald Lloyd Microsoft Excel Programming 2 3rd Aug 2003 04:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:56 AM.