Test if file exists before displaying with XMLHTTP


G

Giles

I have a left menu that is accessed and displayed via XMLHTTP (it resides on
the same server). Some sections of the web site don't have a "menu.asp", so
a "Page Not Found" page is returned, which doesn't look great in the menu
column.. Is there a way to know if a page exists before using
xml.responseText to pull it?
(apart from checking the actual text of the returned page to see if it
contains error-like words)
Thanks
Giles
(PS using xmlhttp instead of server.execute as the menu-page needs
processing before displaying)
 
Ad

Advertisements

S

Slim

Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(filespec)) Then
msg = filespec & " exists."
Else
msg = filespec & " doesn't exist."
End If


if you do not know the physical path you can try this

Set pc = Server.CreateObject("MSWC.PermissionChecker")

pc.HasAccess(url)


if you have permissions the file must exist

I have not checked this, but its worth a try
 
Ad

Advertisements

A

Anthony Jones

Giles said:
I have a left menu that is accessed and displayed via XMLHTTP (it resides on
the same server). Some sections of the web site don't have a "menu.asp", so
a "Page Not Found" page is returned, which doesn't look great in the menu
column.. Is there a way to know if a page exists before using
xml.responseText to pull it?
(apart from checking the actual text of the returned page to see if it
contains error-like words)
Thanks
Giles
(PS using xmlhttp instead of server.execute as the menu-page needs
processing before displaying)

Just test the XMLHTTP.Status property after attempting to fetch it. If it's
404 the file didn't exist and the responseText will contain the sites 404
content.

Anthony
 

Top