473,503 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does url exist?

Hi

How do I find out if an url exists? Whar I want is a function like this:

If UrlExists("http://www.test.com/test.html") Then
Response.Write("Yeah!!")
Else
Response.Write("No file :-(")
End If

Can anyone help?

/Henrik
Jul 22 '05 #1
11 10473
http://www.aspfaq.com/2173

--
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.


"Henrik" <no@email.dk> wrote in message
news:42***********************@news.dk.uu.net...
Hi

How do I find out if an url exists? Whar I want is a function like this:

If UrlExists("http://www.test.com/test.html") Then
Response.Write("Yeah!!")
Else
Response.Write("No file :-(")
End If

Can anyone help?

/Henrik

Jul 22 '05 #2
"Henrik" <no@email.dk> wrote in message
news:42***********************@news.dk.uu.net...
Hi

How do I find out if an url exists? Whar I want is a function like this:

If UrlExists("http://www.test.com/test.html") Then
Response.Write("Yeah!!")
Else
Response.Write("No file :-(")
End If

Can anyone help?

/Henrik

Will this help? Watch for word-wrap.

Function UrlExists(URL)
On Error Resume Next
Err.Clear
Dim b
With Server.CreateObject("Microsoft.XMLHTTP")
.Open "GET",URL,False
.Send
b = .ResponseBody
If Err.Number <> 0 Or .Status <> 200 Then
Fetch = False
Exit Function
End If
End With
Fetch = Err.Number = 0
End Function
I think that the object may vary by Windows version:

CreateObject("Microsoft.XMLHTTP")
CreateObject("MSXML2.ServerXMLHTTP")
CreateObject("MSXML2.ServerXMLHTTP.3.0")
So perhaps the following will work (untested):

Function UrlExists(URL)
On Error Resume Next
Err.Clear
Dim booXML
booXML= False
Dim strXML
Dim objXML
Set objXML = Server.CreateObject("Microsoft.XMLHTTP")
If Err.Number = 0 Then
booXML = True
Else
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
If Err.Number = 0 Then
booXML = True
Else
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
If Err.Number = 0 Then
booXML = True
End If
End If
Err.Clear
End If
objXML.Open "GET",URL,False
objXML.Send
strXML = .ResponseText
If Err.Number <> 0 Or objXML.Status <> 200 Then
Fetch = False
Exit Function
End If
Fetch = Err.Number = 0
End Function
Jul 22 '05 #3
> With Server.CreateObject("Microsoft.XMLHTTP")

FYI, this one isn't recommended for use from ASP... MSXML2.ServerXMLHTTP is
much safer.
Jul 22 '05 #4
Here you go.......

example:

http://mysteryfcm.plus.com/misc/urlexists.asp

Code:

http://mysteryfcm.plus.com/misc/urlexists.asp.txt

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Henrik" <no@email.dk> wrote in message news:42***********************@news.dk.uu.net...
Hi

How do I find out if an url exists? Whar I want is a function like this:

If UrlExists("http://www.test.com/test.html") Then
Response.Write("Yeah!!")
Else
Response.Write("No file :-(")
End If

Can anyone help?

/Henrik



Jul 22 '05 #5
Tis a modified version of one of the samples provided in Aaron's link btw.....

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Steven Burn" <so*******@in-time.invalid> wrote in message news:#R**************@TK2MSFTNGP14.phx.gbl...
Here you go.......

example:

http://mysteryfcm.plus.com/misc/urlexists.asp

Code:

http://mysteryfcm.plus.com/misc/urlexists.asp.txt

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Henrik" <no@email.dk> wrote in message news:42***********************@news.dk.uu.net...
Hi

How do I find out if an url exists? Whar I want is a function like this:

If UrlExists("http://www.test.com/test.html") Then
Response.Write("Yeah!!")
Else
Response.Write("No file :-(")
End If

Can anyone help?

/Henrik


Jul 22 '05 #6
Am I missing something here....... this doesn't return a value either way?. Where is the code telling the function to pass Fetch to URLExists? (tried adding that part myself btw and it still didn't return a value....)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"McKirahan" <Ne**@McKirahan.com> wrote in message news:cZ********************@comcast.com...
"Henrik" <no@email.dk> wrote in message
news:42***********************@news.dk.uu.net...
Hi

How do I find out if an url exists? Whar I want is a function like this:

If UrlExists("http://www.test.com/test.html") Then
Response.Write("Yeah!!")
Else
Response.Write("No file :-(")
End If

Can anyone help?

/Henrik



Will this help? Watch for word-wrap.

Function UrlExists(URL)
On Error Resume Next
Err.Clear
Dim b
With Server.CreateObject("Microsoft.XMLHTTP")
.Open "GET",URL,False
.Send
b = .ResponseBody
If Err.Number <> 0 Or .Status <> 200 Then
Fetch = False
Exit Function
End If
End With
Fetch = Err.Number = 0
End Function


I think that the object may vary by Windows version:

CreateObject("Microsoft.XMLHTTP")
CreateObject("MSXML2.ServerXMLHTTP")
CreateObject("MSXML2.ServerXMLHTTP.3.0")


So perhaps the following will work (untested):

Function UrlExists(URL)
On Error Resume Next
Err.Clear
Dim booXML
booXML= False
Dim strXML
Dim objXML
Set objXML = Server.CreateObject("Microsoft.XMLHTTP")
If Err.Number = 0 Then
booXML = True
Else
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
If Err.Number = 0 Then
booXML = True
Else
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
If Err.Number = 0 Then
booXML = True
End If
End If
Err.Clear
End If
objXML.Open "GET",URL,False
objXML.Send
strXML = .ResponseText
If Err.Number <> 0 Or objXML.Status <> 200 Then
Fetch = False
Exit Function
End If
Fetch = Err.Number = 0
End Function



Jul 22 '05 #7
In the xmlhttp.open call consider changing the HTTP method from GET to HEAD.

The HEAD method will return only the headers, not the whole document. i.e.
HEAD is faster than GET. Since the point is only to check for the existence
of some resource at the specified URL, HEAD is sufficient.

(What's the HEAD method for? Browsers and proxy servers can use the HEAD
method to check if a cached page has been updated.)
"Steven Burn" <so*******@in-time.invalid> wrote in message
news:eT**************@TK2MSFTNGP09.phx.gbl...
Tis a modified version of one of the samples provided in Aaron's link
btw.....

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Steven Burn" <so*******@in-time.invalid> wrote in message
news:#R**************@TK2MSFTNGP14.phx.gbl...
Here you go.......

example:

http://mysteryfcm.plus.com/misc/urlexists.asp

Code:

http://mysteryfcm.plus.com/misc/urlexists.asp.txt

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Henrik" <no@email.dk> wrote in message
news:42***********************@news.dk.uu.net...
Hi

How do I find out if an url exists? Whar I want is a function like this:

If UrlExists("http://www.test.com/test.html") Then
Response.Write("Yeah!!")
Else
Response.Write("No file :-(")
End If

Can anyone help?

/Henrik


Jul 22 '05 #8
Duly changed.... ;o)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Jonathan Dodds" <NO_REPLY> wrote in message news:uf**************@tk2msftngp13.phx.gbl...
In the xmlhttp.open call consider changing the HTTP method from GET to HEAD.

The HEAD method will return only the headers, not the whole document. i.e.
HEAD is faster than GET. Since the point is only to check for the existence
of some resource at the specified URL, HEAD is sufficient.

(What's the HEAD method for? Browsers and proxy servers can use the HEAD
method to check if a cached page has been updated.)


"Steven Burn" <so*******@in-time.invalid> wrote in message
news:eT**************@TK2MSFTNGP09.phx.gbl...
Tis a modified version of one of the samples provided in Aaron's link
btw.....

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Steven Burn" <so*******@in-time.invalid> wrote in message
news:#R**************@TK2MSFTNGP14.phx.gbl...
Here you go.......

example:

http://mysteryfcm.plus.com/misc/urlexists.asp

Code:

http://mysteryfcm.plus.com/misc/urlexists.asp.txt

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Henrik" <no@email.dk> wrote in message
news:42***********************@news.dk.uu.net...
Hi

How do I find out if an url exists? Whar I want is a function like this:

If UrlExists("http://www.test.com/test.html") Then
Response.Write("Yeah!!")
Else
Response.Write("No file :-(")
End If

Can anyone help?

/Henrik





Jul 22 '05 #9
"Steven Burn" <so*******@in-time.invalid> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
Am I missing something here....... this doesn't return a value either way?.
Where is the code telling the function to pass Fetch to URLExists? (tried
adding that part myself btw and it still didn't return a value....)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

[snip]

Yeah, me bad.

I renamed the function without renaming it within itself.

Try this:

If UrlExists("http://www.test.com/test.html") Then
Response.Write("Yeah!!")
Else
Response.Write("No file :-(")
End If

Function UrlExists(xURL)
On Error Resume Next
Err.Clear
With CreateObject("MSXML2.ServerXMLHTTP")
.Open "HEAD",xURL,False
.Send
If Err.Number <> 0 Or .Status <> 200 Then
UrlExists = False
Exit Function
End If
End With
UrlExists = Err.Number = 0
End Function

Thanks to:
Aaron (re "MSXML2.ServerXMLHTTP")
Jonathan (re "HEAD")
Jul 22 '05 #10
I think that he renamed another function when creating the example for you.
Change "Fetch" to "UrlExists"

--
--Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com

"Steven Burn" <so*******@in-time.invalid> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
Am I missing something here....... this doesn't return a value either way?.
Where is the code telling the function to pass Fetch to URLExists? (tried
adding that part myself btw and it still didn't return a value....)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:cZ********************@comcast.com...
"Henrik" <no@email.dk> wrote in message
news:42***********************@news.dk.uu.net...
Hi

How do I find out if an url exists? Whar I want is a function like this:

If UrlExists("http://www.test.com/test.html") Then
Response.Write("Yeah!!")
Else
Response.Write("No file :-(")
End If

Can anyone help?

/Henrik

Will this help? Watch for word-wrap.

Function UrlExists(URL)
On Error Resume Next
Err.Clear
Dim b
With Server.CreateObject("Microsoft.XMLHTTP")
.Open "GET",URL,False
.Send
b = .ResponseBody
If Err.Number <> 0 Or .Status <> 200 Then
Fetch = False
Exit Function
End If
End With
Fetch = Err.Number = 0
End Function
I think that the object may vary by Windows version:

CreateObject("Microsoft.XMLHTTP")
CreateObject("MSXML2.ServerXMLHTTP")
CreateObject("MSXML2.ServerXMLHTTP.3.0")
So perhaps the following will work (untested):

Function UrlExists(URL)
On Error Resume Next
Err.Clear
Dim booXML
booXML= False
Dim strXML
Dim objXML
Set objXML = Server.CreateObject("Microsoft.XMLHTTP")
If Err.Number = 0 Then
booXML = True
Else
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
If Err.Number = 0 Then
booXML = True
Else
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
If Err.Number = 0 Then
booXML = True
End If
End If
Err.Clear
End If
objXML.Open "GET",URL,False
objXML.Send
strXML = .ResponseText
If Err.Number <> 0 Or objXML.Status <> 200 Then
Fetch = False
Exit Function
End If
Fetch = Err.Number = 0
End Function

Jul 22 '05 #11
I tried that before mentioning it and it still wouldn't work on this PC (as I mentioned, it didn't return a value either way, nor did it return an error)..... I basically had to strip out all of the If's/Then's for the different XMLHTTP versions and just leave MSXML2.ServerXMLHTTP for it to work.....

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Mark Schupp" <no******@email.net> wrote in message news:eP**************@tk2msftngp13.phx.gbl...
I think that he renamed another function when creating the example for you.
Change "Fetch" to "UrlExists"

--
--Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com

"Steven Burn" <so*******@in-time.invalid> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
Am I missing something here....... this doesn't return a value either way?.
Where is the code telling the function to pass Fetch to URLExists? (tried
adding that part myself btw and it still didn't return a value....)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:cZ********************@comcast.com...
"Henrik" <no@email.dk> wrote in message
news:42***********************@news.dk.uu.net...
Hi

How do I find out if an url exists? Whar I want is a function like this:

If UrlExists("http://www.test.com/test.html") Then
Response.Write("Yeah!!")
Else
Response.Write("No file :-(")
End If

Can anyone help?

/Henrik

Will this help? Watch for word-wrap.

Function UrlExists(URL)
On Error Resume Next
Err.Clear
Dim b
With Server.CreateObject("Microsoft.XMLHTTP")
.Open "GET",URL,False
.Send
b = .ResponseBody
If Err.Number <> 0 Or .Status <> 200 Then
Fetch = False
Exit Function
End If
End With
Fetch = Err.Number = 0
End Function
I think that the object may vary by Windows version:

CreateObject("Microsoft.XMLHTTP")
CreateObject("MSXML2.ServerXMLHTTP")
CreateObject("MSXML2.ServerXMLHTTP.3.0")
So perhaps the following will work (untested):

Function UrlExists(URL)
On Error Resume Next
Err.Clear
Dim booXML
booXML= False
Dim strXML
Dim objXML
Set objXML = Server.CreateObject("Microsoft.XMLHTTP")
If Err.Number = 0 Then
booXML = True
Else
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
If Err.Number = 0 Then
booXML = True
Else
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
If Err.Number = 0 Then
booXML = True
End If
End If
Err.Clear
End If
objXML.Open "GET",URL,False
objXML.Send
strXML = .ResponseText
If Err.Number <> 0 Or objXML.Status <> 200 Then
Fetch = False
Exit Function
End If
Fetch = Err.Number = 0
End Function




Jul 22 '05 #12

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

Similar topics

1
3638
by: francescomoi | last post by:
Hi. I wonder wether this function exists or not: insertstr($string1, $string2, $position) This function inserts 'string1' into 'string2' at 'position'. If it exists, ok. If not, I'll write it...
20
10083
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
4
1905
by: strnbrg | last post by:
I'd like to write code that fails to compile if a certain function *does* exist in a 3rd party library. (This is the opposite of the well-known problem of wanting compilation to fail if a certain...
5
2021
by: Reader | last post by:
Here is the story. I have my ASP.Net web appliacation that when I uninstall an old version and install a new version the old version's assemblies are still in the system somewhere and cause the...
2
1599
by: tshad | last post by:
I am getting an error on a object name that doesn't exist (according to asp.net), but if you look at the trace, it does. Here is the error: ...
2
9501
by: Iker Arizmendi | last post by:
Using psql and running as the owner of the table "app" I try to access the columns of the table like so: SELECT * FROM app; which returns all the columns in the table including the one I'm...
3
323
by: Mike | last post by:
Thanks for the reply, I have been trying that, but I keep getting the same results. The result I get is that the file exits, when it really doesn't. All my msgbox display twice and I'm not sure...
3
2831
by: MD | last post by:
Hi, I have a variable which is defined inside a class method. When I call PyModule_GetDict on the module containing this class, the dictionary doesn't contain any information about this...
20
3633
by: Bob Sanderson | last post by:
This is my code: if (file_exists($Fname)) { echo "<td>$Fname exists</td>"; } else { echo "<td>$Fname does not exist</td>"; } $Fname is the full path to the file I'm trying to verify. When I...
2
3160
by: =?Utf-8?B?UGF1bCBMaW52aWxsZQ==?= | last post by:
I have a solution that has both c# and vb.net projects. Visual Studio 2005 sp1. One of the lower level asseblies "Utils.csproj" is a c# project that references a 3rd party dll "Framework.dll"....
0
7287
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,...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
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...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4689
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
401
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.