473,396 Members | 1,693 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.

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

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)
Feb 1 '07 #1
6 2723
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
--
Feb 1 '07 #2
Daniel Padron <ng*********@spamgourmet.comwrote:
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
Feb 1 '07 #3
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.
Feb 1 '07 #4
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" <ng*********@spamgourmet.comschreef in bericht
news:Xn********************@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)

Feb 1 '07 #5
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.

Feb 1 '07 #6
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>
Feb 1 '07 #7

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

Similar topics

5
by: Tongu? Yumruk | last post by:
I have a little proposal about type checking in python. I'll be glad if you read and comment on it. Sorry for my bad english (I'm not a native English speaker) A Little Stricter Typing in Python...
67
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. ...
5
by: Timo | last post by:
I am having a problem with some preprocessor constant value checking: header.h: #define MY_CONSTANT 1 file.c #if MY_CONSTANTTT == 1 // <- note the typo!! // dostuff...
30
by: Michael B Allen | last post by:
I have a general purpose library that has a lot of checks for bad input parameters like: void * linkedlist_get(struct linkedlist *l, unsigned int idx) { if (l == NULL) { errno = EINVAL;...
6
by: RoSsIaCrIiLoIA | last post by:
Do you know how to write a self-checking program in standard C? Do I can think that if I write in a file.c static g="1234567"; in the file.exe (or file) there is in some place...
8
by: J-P-W | last post by:
Hi, anyone got any thoughts on this problem? I have sales reps. that remotely send their data to an ftp server. The office downloads all files, the code creates an empty file, then downloads the...
19
by: jeremyz | last post by:
Hi all, I am not a developer, but I work with several and am posting this for them. We are trying to determine whether it is possible to check the size of a file before a user uploads it. ...
1
by: halcyon943 | last post by:
have 4 folders that I watch and need to move files from to another location. Three constraints: -Finish time. Make sure the program stops transferring files at a specific time -Number of...
11
by: Bryan Crouse | last post by:
I am looking a way to do error checking on a string at compile time, and if the string isn't the correct length have then have the compiler throw an error. I am working an embedded software that...
7
by: polas | last post by:
Afternoon everyone. I have a quick question about standard C. Generally speaking, in my experience, whenever one accesses an array there is never any bounds checking done (either statically...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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.