 |
| Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

July 30th, 2004, 05:02 AM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
checking file exists on remote server
Hi all,
I need to check if an image exists on a remote server before showing it on a classic .asp page.
Ive used IfFileExists() before but this doesnt work for remote servers...Does anyone know how I can do this? (Ive tried Googling and Yahooing but couldnt find anything...)
Thanks,
Pete
|
|

July 30th, 2004, 05:19 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hai Pete,
The following code will do this.
dim objFileSystem
Set objFileSystem=Server.CreateObject("Scripting.FileS ystemObject")
if(objFileSystem.FileExists(<absolute-path-of-file>\filename) then
Response.Write("File exists.")
else
Response.Write("File does not exist.")
end if
To get the absolute path of the file, you can use the following command.
Server.Mappath(<relative path of file in relation to the folder where the script resides>)
For e.g. Server.MapPath(".") will give the absolute path of the script file itself.
|
|

July 30th, 2004, 05:43 AM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Cheers for the reply mad.
Just tried it for an example:
http://www.vinyladdict.co.uk/images/va_logo.gif
it doesnt work though. Liek I said earlier I think it's because FileExists only works on the local server.
|
|

July 30th, 2004, 06:10 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hai Pete,
FileExists works in both local server and remote server. I just had a check now. The problem may be that the user IUSR_<machine name> do not have read permission on the folder (images) on remote server.
You need to contact server admin for rectifying this.
|
|

July 30th, 2004, 06:13 AM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ive just tried:
Code:
Function CheckRemoteURL(fileURL)
Dim xmlhttp
Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "HEAD", fileURL, False
xmlhttp.send
Select Case Cint(xmlhttp.status)
Case 200, 202, 302
Set xmlhttp = Nothing
DoesFileExist = True
Case Else
Set xmlhttp = Nothing
DoesFileExist = False
End Select
End Function
but this wont work -
"Error Type:
msxml3.dll (0x80072EFD)
A connection with the server could not be established "
|
|

July 30th, 2004, 06:37 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Oh, When you mentioned local and remote, I thought you are talking about your development server and remote production server. Sorry for the confusion.
In this situation, you can write it like this.
Function CheckRemoteURL(fileURL)
ON ERROR RESUME NEXT
Dim xmlhttp
Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", fileURL, False
xmlhttp.send
If(Err.Number<>0) then
Response.Write "Could not connect to remote server"
else
Select Case Cint(xmlhttp.status)
Case 200, 202, 302
Set xmlhttp = Nothing
DoesFileExist = True
Case Else
Set xmlhttp = Nothing
DoesFileExist = False
End Select
end if
ON ERROR GOTO 0
End Function
|
|

July 30th, 2004, 08:09 AM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I just keep getting the "Could not connect to remote server" message.
:(
|
|

July 31st, 2004, 01:03 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Here are the files I changed. These are working correctly in my browser (IE 6.0)
'test.asp
<%@Language="VBScript"%>
<%
option explicit
Server.ScriptTimeOut=300
response.buffer=false
Response.AddHeader "Pragma","no-cache"
Response.AddHeader "cache-control","no-cache,must revalidate"
Response.Expires =-1
%>
<html>
<head>
<title>XMLHTTP</title>
</head>
<body>
<%
Dim xmlhttp
Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "HEAD", "http://www.vinyladdict.co.uk/images/va_logo.gif", False
xmlhttp.send
Select Case Cint(xmlhttp.status)
Case 200, 202, 302
Set xmlhttp = Nothing
Response.Write("http://www.vinyladdict.co.uk/images/va_logo.gif exists")
Case Else
Set xmlhttp = Nothing
Response.Write("http://www.vinyladdict.co.uk/images/va_logo.gif does not exist")
End Select
%>
</body>
</html>
' test1.asp
<%@Language="VBScript"%>
<%
option explicit
Server.ScriptTimeOut=300
response.buffer=false
Response.AddHeader "Pragma","no-cache"
Response.AddHeader "cache-control","no-cache,must revalidate"
Response.Expires =-1
%>
<html>
<head>
<title>XMLHTTP</title>
</head>
<body>
<%
Dim xmlhttp
Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "HEAD", "http://www.vinyladdict.co.uk/images/va_logo1.gif", False
xmlhttp.send
Select Case Cint(xmlhttp.status)
Case 200, 202, 302
Set xmlhttp = Nothing
Response.Write("http://www.vinyladdict.co.uk/images/va_logo1.gif exists")
Case Else
Set xmlhttp = Nothing
Response.Write("http://www.vinyladdict.co.uk/images/va_logo1.gif does not exist")
End Select
%>
</body>
</html>
I have not made any change to your script. May be the variable fileURL not set. Please check it.
|
|

July 31st, 2004, 09:18 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hey pete_m,
I get the result as TRUE to this code. Looks like you got to upgrade to the recent XML3.0 service pack
Code:
<%
Function CheckRemoteURL(fileURL)
ON ERROR RESUME NEXT
Dim xmlhttp
Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", fileURL, False
xmlhttp.send
If(Err.Number<>0) then
Response.Write "Could not connect to remote server"
else
Select Case Cint(xmlhttp.status)
Case 200, 202, 302
Set xmlhttp = Nothing
CheckRemoteURL = True
Case Else
Set xmlhttp = Nothing
CheckRemoteURL = False
End Select
end if
ON ERROR GOTO 0
End Function
Response.write CheckRemoteURL("http://www.vinyladdict.co.uk/images/va_logo.gif")
%>
You can also try that using
Set xmlhttp = Server.CreateObject("Microsoft.XMLHTTP")
or
Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
All that works fine with my setup.
There seems to be this bug(resulting in error that you face) in XML 3.0 (before service pack 2). But this has been fixed in the Microsoft XML 3.0 Service Pack 2 (Part 3 of 4)
You can download the latest XML 3.0 service packs from - Microsoft XML Parser (MSXML) 3.0 Service Pack 4 (SP4)
Hope that helps.
Cheers!
_________________________
- Vijay G
Strive for Perfection
|
|

July 31st, 2004, 08:38 PM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Vijay, will try first thing Monday morning
btw: Does this mean all the clients using the page require the new XML service pack?
(Should be OK)
thanks again,
Pete
|
|
 |