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")

EndIf

EndSub

[1338 byte] By [James883] at [2008-1-10]
# 1

Use the System.Net.FileWebRequest

Code Snippet

Dim objFileRequest As System.Net.HttpWebRequest

objFileRequest = System.Net.FileWebRequest.Create("http://534653.free-web-hosting.biz/default.html")

Try

objFileRequest.GetResponse()

MsgBox("File exists")

Catch ex As Exception

MsgBox("File doesn't exists")

End Try

objFileRequest = Nothing

AmrOuf at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
This is not going to work. The web server will typically generate a 404 response page. You'll need an FTP server.
nobugz at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
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
AmrOuf at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4
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.
nobugz at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5

The script just sees if the

http://534653.free-web-hosting.biz/

is there

it does not check if that file is actually there, i've asking it to search:

http://534653.free-web-hosting.biz/senhjfbgdfbgfhgdfsg.html

which i know theres not a file there called well that. But it still says file found. But i tried another site:

http://www.fbfdfdfsnagnbvfvakfgagf.com/

Which its says it says files does not exist.

James883 at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 6
so it only sees if the websites exists not the files within the site.
James883 at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 7
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.
James883 at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 8
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.
nobugz at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...