Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I test to see if a web page exists?

Status
Not open for further replies.

yuli1104

Programmer
Feb 20, 2002
60
CA
Hello friends,

How can I use asp to test if a web page is availabe ? I know how to test if the site server (host) is running. For example, I can test if " is available by using Server.CreateObjec ("Microsoft.XMLhttp"). My question is how can I test a specific page such as " is available ?

Any Idea is appreciated !

Yuli
 
copy/paste from
<html>
<body>

<%
Set fs=Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

If (fs.FileExists(&quot;c:\winnt\cursors\3dgarro.cur&quot;))=true Then
Response.Write(&quot;File c:\winnt\cursors\3dgarro.cur exists.&quot;)
Else
Response.Write(&quot;File c:\winnt\cursors\3dgarro.cur does not exist.&quot;)
End If

set fs=nothing
%>

</body>
</html> _________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
 
Onpnt, thank you for your reply. But I need to test if a web page on a remote server is available . Your answer can only test a file's existance on a networked drive. ??

Yuli
 
Well, you could use XMLHTTP to request the page and then check the status (similar to how your browser does it). Any status but 200 means there was an issue with the page you were trying to get, either no there, error, etc

Here is a reference for the object with examples:
I actually had to google for that one, I always forget where w3schools keeps it hidden :)

-Tarwn ________________________________________________
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
Code:
Sub Macro4()
'
' Macro4 Macro
' Macro recorded 05/02/2003 by AMacdonald
'
Dim sTemp
sTemp = GetStatus(&quot;[URL unfurl="true"]http://www.tek-tips.com/submitpost.cfm&quot;)[/URL]

If InStr(sTemp, &quot;404&quot;) > 0 Then
sTemp = sTemp & vbCr & &quot; - this means the file was not found&quot;
End If

MsgBox sTemp
End Sub


Function GetStatus(strURL)
'Dim objXMLHTTP, strReturn
'Set objXMLHTTP = Server.CreateObject(&quot;Microsoft.XMLHTTP&quot;)
Dim ttw As New xmlhttp
ttw.Open &quot;GET&quot;, strURL, False
ttw.send

strReturn = ttw.Status & &quot; / &quot; & ttw.StatusText
Set ttw = Nothing

GetStatus = strReturn

End Function

I think though that if they have custom server pages it doesn't send back 404 - I tried on our intranet and got 500 back.
Regards
Alasdair
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top