Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 30th, 2004, 05:02 AM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

Reply With Quote
  #2 (permalink)  
Old July 30th, 2004, 05:19 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cochin, Kerala, India.
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

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.
Reply With Quote
  #3 (permalink)  
Old July 30th, 2004, 05:43 AM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
  #4 (permalink)  
Old July 30th, 2004, 06:10 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cochin, Kerala, India.
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

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.
Reply With Quote
  #5 (permalink)  
Old July 30th, 2004, 06:13 AM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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 "



Reply With Quote
  #6 (permalink)  
Old July 30th, 2004, 06:37 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cochin, Kerala, India.
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

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
Reply With Quote
  #7 (permalink)  
Old July 30th, 2004, 08:09 AM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I just keep getting the "Could not connect to remote server" message.

:(

Reply With Quote
  #8 (permalink)  
Old July 31st, 2004, 01:03 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cochin, Kerala, India.
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

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.
Reply With Quote
  #9 (permalink)  
Old July 31st, 2004, 09:18 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
Reply With Quote
  #10 (permalink)  
Old July 31st, 2004, 08:38 PM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot delete file from Remote server. snowbydave1 PHP FAQs 0 March 7th, 2007 02:52 AM
Determining if a Remote File Exists hugh@kmcnetwork.com VB How-To 1 January 5th, 2007 11:56 PM
hei,anyone know how to check a remote file exists lsj113 C# 2005 3 November 28th, 2006 02:55 AM
Checking if a specific template exists sl0th XSLT 3 October 1st, 2006 03:14 AM
Checking to see if record exists EmmaGale Classic ASP Basics 6 March 14th, 2006 02:39 AM



All times are GMT -4. The time now is 01:03 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.