Check that a online file exists (EG: 'www.files.com/file.html') and returns a True or
I was wondering if theres a simple code which checks if a file exists and returns a result 'True or False' the below code does not work of course but is there a a code like this one?
PrivateSub Label5_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles Label5.Click
If URL("http://534653.free-web-hosting.biz/default.html")Then
MsgBox(
"FILE found"
, MsgBoxStyle.Critical,"FEEDBACK"
)Else
MsgBox(
"FILE not found"
, MsgBoxStyle.Critical,"FEDBACK"
)End
If
End
Sub
[1338 byte] By [
James883] at [2008-1-10]
Dear nobugs,
I wonder did you test this code to say it will not going to work?
It's been tested and working fine, when this code enters the exception it's usually 404.
Dear James,
This code will attempt to seek the file you are asking for by the GetResponse().
This is typically as Open file, and we have no intention to read the file, so if GetResponse didn't throw the exception as described by nobugs the file should exist other wise it doesn't.
This is tested on both of HTTP and FTP Files.
Good Luck,
Amr Ouf
Yes, I tested it using that same website but asking for blabla.htm. I did use WebRequest.Create() though, the FileWebRequest constructor is deprecated. I got a HTML page with a 302 response with a 200 status. Most web servers I know have a custom 404 response page.
I am asking everyone this because i want to create a web browser in which if theres updates, (by searching if a file/folder exists, it will download them overwriting the current application with a more updated version. Of course with confirmation of the user before any download commences.
As I said, the HTTP protocol is just not sophisticated enough to do this. If you can't use an FTP server, your only option is to actually download the file and do a binary comparison. If there's a difference, you'll have to assume that the downloaded one is a recent revision.