objFSO.FileExists not working?????

Discussion in 'ASP General' started by Rudi Ahlers, Apr 10, 2004.

  1. Rudi Ahlers

    Rudi Ahlers Guest

    I have the following link: http://hobbit/newhp/index.asp?l=advert, and it
    doesn't do what I want it to do, even though the file exists.
    If a file doesn't exist, it should use home.asp as default, yet it uses
    home.asp as default regardless if the file exists or not?
    Here is the script:


    linkname = request.QueryString("l")

    if linkname <> "" then
    page = linkname & ".html"
    If objFSO.FileExists(page) = false Then
    page = "home.asp"
    End If
    end if

    If http://hobbit/newhp/index.asp?l=advert123 (which doesn't exist) it goes
    to home.asp, which is what I want, but it also does it for all the files
    that does exist, and reason for that?

    --

    Kind Regards
    Rudi Ahlers
    +27 (82) 926 1689

    Greater love has no one than this, that he lay down his life for his friends
    (John 15:13).
     
    Rudi Ahlers, Apr 10, 2004
    #1
    1. Advertising

  2. Rudi Ahlers

    Steven Burn Guest

    Select Case linkname
    Case ""
    page = "home.asp"
    Case else
    page = linkname & ".html"
    If objFSO.FileExists(page) = false Then
    page = "home.asp"
    else
    page = page
    End If
    End Select

    --
    Regards

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

    Keeping it FREE!

    Disclaimer:
    I know I'm probably wrong, I just like taking part ;o)


    Rudi Ahlers <SP4M_Rudi@SP4M_Bonzai.org.za_SP4M> wrote in message
    news:...
    > I have the following link: http://hobbit/newhp/index.asp?l=advert, and it
    > doesn't do what I want it to do, even though the file exists.
    > If a file doesn't exist, it should use home.asp as default, yet it uses
    > home.asp as default regardless if the file exists or not?
    > Here is the script:
    >
    >
    > linkname = request.QueryString("l")
    >
    > if linkname <> "" then
    > page = linkname & ".html"
    > If objFSO.FileExists(page) = false Then
    > page = "home.asp"
    > End If
    > end if
    >
    > If http://hobbit/newhp/index.asp?l=advert123 (which doesn't exist) it goes
    > to home.asp, which is what I want, but it also does it for all the files
    > that does exist, and reason for that?
    >
    > --
    >
    > Kind Regards
    > Rudi Ahlers
    > +27 (82) 926 1689
    >
    > Greater love has no one than this, that he lay down his life for his

    friends
    > (John 15:13).
    >
    >
     
    Steven Burn, Apr 10, 2004
    #2
    1. Advertising

  3. Rudi Ahlers

    Bob Barrows Guest

    Rudi Ahlers wrote:
    > I have the following link: http://hobbit/newhp/index.asp?l=advert,
    > and it doesn't do what I want it to do, even though the file exists.
    > If a file doesn't exist, it should use home.asp as default, yet it
    > uses home.asp as default regardless if the file exists or not?
    > Here is the script:
    >
    >
    > linkname = request.QueryString("l")
    >
    > if linkname <> "" then
    > page = linkname & ".html"
    > If objFSO.FileExists(page) = false Then
    > page = "home.asp"
    > End If
    > end if
    >
    > If http://hobbit/newhp/index.asp?l=advert123 (which doesn't exist) it
    > goes to home.asp, which is what I want, but it also does it for all
    > the files that does exist, and reason for that?


    Where is the line of code that does the redirection?

    Bob Barrows


    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows, Apr 10, 2004
    #3
  4. Rudi Ahlers

    Lord Merlin Guest

    Bob, this is part of a table structure

    <TR>
    <TD WIDTH="160" HEIGHT="100%" ROWSPAN="3" BGCOLOR="#63526B">
    <!--#include file="menu.html"--> </TD>
    <TD HEIGHT="100%" ROWSPAN="3"><%=server.Execute(page)%></TD>
    <TD WIDTH="25" HEIGHT="100%" ALIGN="RIGHT" VALIGN="TOP"
    BACKGROUND="images/layout/r_b3.gif" BGCOLOR="#FFA531"><IMG
    SRC="images/layout/r_b2.gif" WIDTH="25" HEIGHT="11"></TD>
    </TR>


    and all works fine is I don't include that part where it checks if the file
    exist. But the moment I tell it to check if the file exsits, it doesn't seem
    to play along nicely :)
    --

    Kind Regards
    Rudi Ahlers
    +27 (82) 926 1689

    Greater love has no one than this, that he lay down his life for his friends
    (John 15:13).
    "Bob Barrows" <> wrote in message
    news:...
    Rudi Ahlers wrote:
    > I have the following link: http://hobbit/newhp/index.asp?l=advert,
    > and it doesn't do what I want it to do, even though the file exists.
    > If a file doesn't exist, it should use home.asp as default, yet it
    > uses home.asp as default regardless if the file exists or not?
    > Here is the script:
    >
    >
    > linkname = request.QueryString("l")
    >
    > if linkname <> "" then
    > page = linkname & ".html"
    > If objFSO.FileExists(page) = false Then
    > page = "home.asp"
    > End If
    > end if
    >
    > If http://hobbit/newhp/index.asp?l=advert123 (which doesn't exist) it
    > goes to home.asp, which is what I want, but it also does it for all
    > the files that does exist, and reason for that?


    Where is the line of code that does the redirection?

    Bob Barrows


    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Lord Merlin, Apr 10, 2004
    #4
  5. "Rudi Ahlers" <SP4M_Rudi@SP4M_Bonzai.org.za_SP4M> wrote in message
    news:...
    > I have the following link: http://hobbit/newhp/index.asp?l=advert, and it
    > doesn't do what I want it to do, even though the file exists.
    > If a file doesn't exist, it should use home.asp as default, yet it uses
    > home.asp as default regardless if the file exists or not?
    > Here is the script:
    >
    >
    > linkname = request.QueryString("l")


    Probably you do **not** want your website to *expose* absolute path
    information such as c:\mydata\file.txt

    > if linkname <> "" then
    > page = linkname & ".html"

    go for
    page = Server.MapPath(linkname + ".html")
    where linkname must be a page in relative format like "scripts/mypage.asp"

    > If objFSO.FileExists(page) = false Then
    > page = "home.asp"
    > End If



    > end if
    >
    > If http://hobbit/newhp/index.asp?l=advert123 (which doesn't exist) it goes
    > to home.asp, which is what I want, but it also does it for all the files
    > that does exist, and reason for that?
    >
    > --
    >
    > Kind Regards
    > Rudi Ahlers
    > +27 (82) 926 1689
    >
    > Greater love has no one than this, that he lay down his life for his

    friends
    > (John 15:13).
    >
    >
     
    Egbert Nierop \(MVP for IIS\), Apr 10, 2004
    #5
  6. Rudi Ahlers

    Lord Merlin Guest

    That works rather well, but what are the security implications?
    Can it cause any harm if it's not being displayed? And even if it is? What
    good is it to anyone?

    --

    Kind Regards
    Rudi Ahlers
    +27 (82) 926 1689

    Greater love has no one than this, that he lay down his life for his friends
    (John 15:13).
    "Egbert Nierop (MVP for IIS)" <> wrote in
    message news:...
    "Rudi Ahlers" <SP4M_Rudi@SP4M_Bonzai.org.za_SP4M> wrote in message
    news:...
    > I have the following link: http://hobbit/newhp/index.asp?l=advert, and it
    > doesn't do what I want it to do, even though the file exists.
    > If a file doesn't exist, it should use home.asp as default, yet it uses
    > home.asp as default regardless if the file exists or not?
    > Here is the script:
    >
    >
    > linkname = request.QueryString("l")


    Probably you do **not** want your website to *expose* absolute path
    information such as c:\mydata\file.txt

    > if linkname <> "" then
    > page = linkname & ".html"

    go for
    page = Server.MapPath(linkname + ".html")
    where linkname must be a page in relative format like "scripts/mypage.asp"

    > If objFSO.FileExists(page) = false Then
    > page = "home.asp"
    > End If



    > end if
    >
    > If http://hobbit/newhp/index.asp?l=advert123 (which doesn't exist) it goes
    > to home.asp, which is what I want, but it also does it for all the files
    > that does exist, and reason for that?
    >
    > --
    >
    > Kind Regards
    > Rudi Ahlers
    > +27 (82) 926 1689
    >
    > Greater love has no one than this, that he lay down his life for his

    friends
    > (John 15:13).
    >
    >
     
    Lord Merlin, Apr 10, 2004
    #6
  7. "Lord Merlin" <SP4M_Rudi@SP4M_Bonzai.org.za_SP4M> wrote in message
    news:...
    > That works rather well, but what are the security implications?
    > Can it cause any harm if it's not being displayed? And even if it is? What
    > good is it to anyone?



    No absolute paths should be passed to and from a webserver. I don't quite
    understand your question but figure, a script, on a non completely tested or
    configured site can exploit your \windows\system32 directory. Therefore, use
    relative paths.

    --
    compatible web farm Session replacement for Asp and Asp.Net
    http://www.nieropwebconsult.nl/asp_session_manager.htm
     
    Egbert Nierop \(MVP for IIS\), Apr 10, 2004
    #7
  8. Rudi Ahlers

    Roland Hall Guest

    "Rudi Ahlers" wrote in message news:...
    : I have the following link: http://hobbit/newhp/index.asp?l=advert, and it
    : doesn't do what I want it to do, even though the file exists.
    : If a file doesn't exist, it should use home.asp as default, yet it uses
    : home.asp as default regardless if the file exists or not?
    : Here is the script:
    :
    :
    : linkname = request.QueryString("l")
    :
    : if linkname <> "" then
    : page = linkname & ".html"
    : If objFSO.FileExists(page) = false Then
    : page = "home.asp"
    : End If
    : end if
    :
    : If http://hobbit/newhp/index.asp?l=advert123 (which doesn't exist) it goes
    : to home.asp, which is what I want, but it also does it for all the files
    : that does exist, and reason for that?

    Your code reads as:

    linkname=advert123
    if linkname not empty then
    page = advert.html
    if advert.html not exist then
    page = home.asp
    end if
    endif

    That's why it always hits the home page when the tested file is not present
    although the redirect is not shown here.

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, Apr 11, 2004
    #8
  9. Rudi Ahlers

    Lord Merlin Guest

    I don't quite understand what you mean.

    See, I want to call a page. If no input is given, home.asp should be parsed.
    If an input is given, it should be checked if the file exists, if it doesn't
    parse home.asp again. If the file does exists, parse that file.
    So my logic is right.......

    linkname=advert123 - (i.e
    http://localhost/index.asp?l=advert123)
    if linkname not empty then - (i.e the variable linkname
    contains something)
    ipage = linkname & ".html" - make the page the contents of
    linkname, which will be executed like this: server.execute(page)
    if ipage not exist then - see if the filename being
    called exists, if not
    ipage = "home.asp" - use home.asp
    end if
    endif


    You see, if server.execute is given a blank field to parse, it returns an
    error. Thus I need to know if the file being called actually exists or not.
    And to keep a list of say over 2000 pages long in a case statement is not
    going to work. Rather check if the file being called exists, if it doesn't
    use home.asp as default.

    --

    Kind Regards
    Rudi Ahlers
    +27 (82) 926 1689

    Greater love has no one than this, that he lay down his life for his friends
    (John 15:13).
    "Roland Hall" <nobody@nowhere> wrote in message
    news:...
    "Rudi Ahlers" wrote in message news:...
    : I have the following link: http://hobbit/newhp/index.asp?l=advert, and it
    : doesn't do what I want it to do, even though the file exists.
    : If a file doesn't exist, it should use home.asp as default, yet it uses
    : home.asp as default regardless if the file exists or not?
    : Here is the script:
    :
    :
    : linkname = request.QueryString("l")
    :
    : if linkname <> "" then
    : page = linkname & ".html"
    : If objFSO.FileExists(page) = false Then
    : page = "home.asp"
    : End If
    : end if
    :
    : If http://hobbit/newhp/index.asp?l=advert123 (which doesn't exist) it goes
    : to home.asp, which is what I want, but it also does it for all the files
    : that does exist, and reason for that?

    Your code reads as:

    linkname=advert123
    if linkname not empty then
    page = advert.html
    if advert.html not exist then
    page = home.asp
    end if
    endif

    That's why it always hits the home page when the tested file is not present
    although the redirect is not shown here.

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Lord Merlin, Apr 11, 2004
    #9
  10. Rudi Ahlers

    Bob Barrows Guest

    Use response.write to check the value of the page variable after the if
    statement. You will see...

    Lord Merlin wrote:
    > I don't quite understand what you mean.
    >
    > See, I want to call a page. If no input is given, home.asp should be
    > parsed. If an input is given, it should be checked if the file
    > exists, if it doesn't parse home.asp again. If the file does exists,
    > parse that file.
    > So my logic is right.......
    >
    > linkname=advert123 - (i.e
    > http://localhost/index.asp?l=advert123)
    > if linkname not empty then - (i.e the variable linkname
    > contains something)
    > ipage = linkname & ".html" - make the page the contents
    > of linkname, which will be executed like this: server.execute(page)
    > if ipage not exist then - see if the filename
    > being called exists, if not
    > ipage = "home.asp" - use home.asp
    > end if
    > endif
    >
    >
    > You see, if server.execute is given a blank field to parse, it
    > returns an error. Thus I need to know if the file being called
    > actually exists or not. And to keep a list of say over 2000 pages
    > long in a case statement is not going to work. Rather check if the
    > file being called exists, if it doesn't use home.asp as default.
    >
    > --
    >
    > Kind Regards
    > Rudi Ahlers
    > +27 (82) 926 1689
    >
    > Greater love has no one than this, that he lay down his life for his
    > friends (John 15:13).
    > "Roland Hall" <nobody@nowhere> wrote in message
    > news:...
    > "Rudi Ahlers" wrote in message news:...
    >> I have the following link: http://hobbit/newhp/index.asp?l=advert,
    >> and it doesn't do what I want it to do, even though the file exists.
    >> If a file doesn't exist, it should use home.asp as default, yet it
    >> uses home.asp as default regardless if the file exists or not?
    >> Here is the script:
    >>
    >>
    >> linkname = request.QueryString("l")
    >>
    >> if linkname <> "" then
    >> page = linkname & ".html"
    >> If objFSO.FileExists(page) = false Then
    >> page = "home.asp"
    >> End If
    >> end if
    >>
    >> If http://hobbit/newhp/index.asp?l=advert123 (which doesn't exist)
    >> it goes to home.asp, which is what I want, but it also does it for
    >> all the files that does exist, and reason for that?

    >
    > Your code reads as:
    >
    > linkname=advert123
    > if linkname not empty then
    > page = advert.html
    > if advert.html not exist then
    > page = home.asp
    > end if
    > endif
    >
    > That's why it always hits the home page when the tested file is not
    > present although the redirect is not shown here.




    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows, Apr 11, 2004
    #10
  11. Rudi Ahlers

    Lord Merlin Guest

    --

    Kind Regards
    Rudi Ahlers
    +27 (82) 926 1689

    Greater love has no one than this, that he lay down his life for his friends
    (John 15:13).
    "Bob Barrows" <> wrote in message
    news:...
    : Use response.write to check the value of the page variable after the if
    : statement. You will see...
    :
    : Lord Merlin wrote:
    : > I don't quite understand what you mean.
    : >
    : > See, I want to call a page. If no input is given, home.asp should be
    : > parsed. If an input is given, it should be checked if the file
    : > exists, if it doesn't parse home.asp again. If the file does exists,
    : > parse that file.
    : > So my logic is right.......
    : >
    : > linkname=advert123 - (i.e
    : > http://localhost/index.asp?l=advert123)
    : > if linkname not empty then - (i.e the variable linkname
    : > contains something)
    : > ipage = linkname & ".html" - make the page the contents
    : > of linkname, which will be executed like this: server.execute(page)
    : > if ipage not exist then - see if the filename
    : > being called exists, if not
    : > ipage = "home.asp" - use home.asp
    : > end if
    : > endif
    : >
    : >
    : > You see, if server.execute is given a blank field to parse, it
    : > returns an error. Thus I need to know if the file being called
    : > actually exists or not. And to keep a list of say over 2000 pages
    : > long in a case statement is not going to work. Rather check if the
    : > file being called exists, if it doesn't use home.asp as default.
    : >
    : > --
    : >
    : > Kind Regards
    : > Rudi Ahlers
    : > +27 (82) 926 1689
    : >
    : > Greater love has no one than this, that he lay down his life for his
    : > friends (John 15:13).
    : > "Roland Hall" <nobody@nowhere> wrote in message
    : > news:...
    : > "Rudi Ahlers" wrote in message news:...
    : >> I have the following link: http://hobbit/newhp/index.asp?l=advert,
    : >> and it doesn't do what I want it to do, even though the file exists.
    : >> If a file doesn't exist, it should use home.asp as default, yet it
    : >> uses home.asp as default regardless if the file exists or not?
    : >> Here is the script:
    : >>
    : >>
    : >> linkname = request.QueryString("l")
    : >>
    : >> if linkname <> "" then
    : >> page = linkname & ".html"
    : >> If objFSO.FileExists(page) = false Then
    : >> page = "home.asp"
    : >> End If
    : >> end if
    : >>
    : >> If http://hobbit/newhp/index.asp?l=advert123 (which doesn't exist)
    : >> it goes to home.asp, which is what I want, but it also does it for
    : >> all the files that does exist, and reason for that?
    : >
    : > Your code reads as:
    : >
    : > linkname=advert123
    : > if linkname not empty then
    : > page = advert.html
    : > if advert.html not exist then
    : > page = home.asp
    : > end if
    : > endif
    : >
    : > That's why it always hits the home page when the tested file is not
    : > present although the redirect is not shown here.
    :
    :
    :
    : --
    : Microsoft MVP - ASP/ASP.NET
    : Please reply to the newsgroup. This email account is my spam trap so I
    : don't check it very often. If you must reply off-line, then remove the
    : "NO SPAM"
    :
    :
    Seems like Server.MapPath does the trick though:

    if linkname <> "" then
    page = linkname & ".html"
    If objFSO.FileExists(server.MapPath(page)) = false Then
    page = "home.asp"
    End If
    end if
     
    Lord Merlin, Apr 11, 2004
    #11
  12. Rudi Ahlers

    Roland Hall Guest

    "Lord Merlin" wrote in message news:...
    : Seems like Server.MapPath does the trick though:
    :
    : if linkname <> "" then
    : page = linkname & ".html"
    : If objFSO.FileExists(server.MapPath(page)) = false Then
    : page = "home.asp"
    : End If
    : end if

    This conditional:
    If objFSO.FileExists(server.MapPath(page)) = false Then
    page = "home.asp"
    End If

    If true = false? objFSO.FileExists(Server.MapPath(page)) returns true if
    the file exists and then you're testing that result to see if it = false,
    which is always false.

    It should be:
    if objFSO.FileExists(server.MapPath(page)) Then
    page = "home.asp"
    end if

    HTH...

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, Apr 12, 2004
    #12
  13. Rudi Ahlers

    Lord Merlin Guest

    "Roland Hall" <nobody@nowhere> wrote in message
    news:...
    : "Lord Merlin" wrote in message news:...
    : : Seems like Server.MapPath does the trick though:
    : :
    : : if linkname <> "" then
    : : page = linkname & ".html"
    : : If objFSO.FileExists(server.MapPath(page)) = false Then
    : : page = "home.asp"
    : : End If
    : : end if
    :
    : This conditional:
    : If objFSO.FileExists(server.MapPath(page)) = false Then
    : page = "home.asp"
    : End If
    :
    : If true = false? objFSO.FileExists(Server.MapPath(page)) returns true if
    : the file exists and then you're testing that result to see if it = false,
    : which is always false.
    :
    : It should be:
    : if objFSO.FileExists(server.MapPath(page)) Then
    : page = "home.asp"
    : end if
    :
    : HTH...
    :
    : --
    : Roland Hall
    : /* This information is distributed in the hope that it will be useful, but
    : without any warranty; without even the implied warranty of merchantability
    : or fitness for a particular purpose. */
    : Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    : WSH 5.6 Documentation -
    http://msdn.microsoft.com/downloads/list/webdev.asp
    : MSDN Library - http://msdn.microsoft.com/library/default.asp
    :
    :
    Hold on, if it always returns true, then how would I check if a page doesn't
    exist.

    See, if a page does not exist, I want it to redirect to home.asp. But, if
    this statement always returns true, then is means it will return true if the
    file exists (let's say advert.asp), so then I can't use the following
    statement.
    if objFSO.FileExists(server.MapPath(page)) Then
    page = "home.asp"
    end if

    --

    Kind Regards
    Rudi Ahlers
    +27 (82) 926 1689

    Greater love has no one than this, that he lay down his life for his friends
    (John 15:13).
     
    Lord Merlin, Apr 12, 2004
    #13
  14. Rudi Ahlers

    Roland Hall Guest

    "Lord Merlin" wrote in message news:...
    : "Roland Hall" <nobody@nowhere> wrote in message
    : news:...
    : : "Lord Merlin" wrote in message news:...
    : : : Seems like Server.MapPath does the trick though:
    : : :
    : : : if linkname <> "" then
    : : : page = linkname & ".html"
    : : : If objFSO.FileExists(server.MapPath(page)) = false Then
    : : : page = "home.asp"
    : : : End If
    : : : end if
    : :
    : : This conditional:
    : : If objFSO.FileExists(server.MapPath(page)) = false Then
    : : page = "home.asp"
    : : End If
    : :
    : : If true = false? objFSO.FileExists(Server.MapPath(page)) returns true
    if
    : : the file exists and then you're testing that result to see if it =
    false,
    : : which is always false.
    : :
    : : It should be:
    : : if objFSO.FileExists(server.MapPath(page)) Then
    : : page = "home.asp"
    : : end if
    : :
    : : HTH...
    : :
    : : --
    : : Roland Hall
    : : /* This information is distributed in the hope that it will be useful,
    but
    : : without any warranty; without even the implied warranty of
    merchantability
    : : or fitness for a particular purpose. */
    : : Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    : : WSH 5.6 Documentation -
    : http://msdn.microsoft.com/downloads/list/webdev.asp
    : : MSDN Library - http://msdn.microsoft.com/library/default.asp
    : :
    : :
    : Hold on, if it always returns true, then how would I check if a page
    doesn't
    : exist.
    :
    : See, if a page does not exist, I want it to redirect to home.asp. But, if
    : this statement always returns true, then is means it will return true if
    the
    : file exists (let's say advert.asp), so then I can't use the following
    : statement.
    : if objFSO.FileExists(server.MapPath(page)) Then
    : page = "home.asp"
    : end if

    Rudi...

    I'd draw you a picture but they don't accept embedded graphics.

    This is boolean logic. True|False, Yes|No, -1|0

    FileExists DOES NOT always return true.

    When testing to see if a file exists with: if
    objFSO.FileExists(Server.MapPath(page))
    .... if the file DOES EXIST, then it will return TRUE. If it does NOT EXIST,
    then it will return FALSE.

    If you look for a file that DOES EXIST and it returns TRUE and then you test
    to see if it is equal to false, THAT result will always return false,
    because TRUE != FALSE

    When you add " = false " on the end of: " if
    objFSO.FileExists(Server.MapPath(page)), you are performing two tests.

    1. See if the file exists and if it does return true
    2. Now compare the result [in this case true] to see if it is equal to false
    [which it is NOT].

    Correct:
    if objFSO.FileExists(Server.MapPath(page)) Then

    Incorrect
    if objFSO.FileExists(Server.MapPath(page)) = false Then

    Take out = false and move on.

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp




    Take out " = false " from your statement.
     
    Roland Hall, Apr 13, 2004
    #14
  15. Rudi Ahlers

    Bob Barrows Guest

    Roland Hall wrote:
    > Correct:
    > if objFSO.FileExists(Server.MapPath(page)) Then
    >
    > Incorrect
    > if objFSO.FileExists(Server.MapPath(page)) = false Then
    >
    > Take out = false and move on.


    Just to expand on what Roland is trying to get across, the following
    statements are equivalent:

    if objFSO.FileExists(Server.MapPath(page)) Then
    if objFSO.FileExists(Server.MapPath(page))=true Then
    if NOT objFSO.FileExists(Server.MapPath(page)) = false Then
    if objFSO.FileExists(Server.MapPath(page)) <> false Then

    The following statements are also equivalent:

    if objFSO.FileExists(Server.MapPath(page)) = false Then
    if NOT objFSO.FileExists(Server.MapPath(page)) Then
    if NOT objFSO.FileExists(Server.MapPath(page))=true Then
    if objFSO.FileExists(Server.MapPath(page)) <> true Then

    > See, if a page does not exist, I want it to redirect to home.asp.
    > But, if this statement always returns true, then is means it will
    > return true if the file exists (let's say advert.asp), so then I


    Here is what I meant about using response.write for debugging your code:

    if linkname <> "" then
    page = linkname & ".html"
    'for debugging:
    response.write "Before IF statement:<BR>"
    response.write server.MapPath(page) & "<BR>"
    response.write "objFSO.FileExists(server.MapPath(page)) returns "
    response.write objFSO.FileExists(server.MapPath(page)) & "<BR>"
    'comment out the above lines when finished debugging

    If objFSO.FileExists(server.MapPath(page)) = false Then
    page = "home.asp"
    End If
    end if
    'for debugging:
    response.write "After IF statement:<BR>"
    response.write page
    response.end
    'comment out the above lines when finished debugging

    Bob Barrows
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows, Apr 13, 2004
    #15
  16. Rudi Ahlers

    Lord Merlin Guest

    "Bob Barrows" <> wrote in message
    news:#...
    : Roland Hall wrote:
    : > Correct:
    : > if objFSO.FileExists(Server.MapPath(page)) Then
    : >
    : > Incorrect
    : > if objFSO.FileExists(Server.MapPath(page)) = false Then
    : >
    : > Take out = false and move on.
    :
    : Just to expand on what Roland is trying to get across, the following
    : statements are equivalent:
    :
    : if objFSO.FileExists(Server.MapPath(page)) Then
    : if objFSO.FileExists(Server.MapPath(page))=true Then
    : if NOT objFSO.FileExists(Server.MapPath(page)) = false Then
    : if objFSO.FileExists(Server.MapPath(page)) <> false Then
    :
    : The following statements are also equivalent:
    :
    : if objFSO.FileExists(Server.MapPath(page)) = false Then
    : if NOT objFSO.FileExists(Server.MapPath(page)) Then
    : if NOT objFSO.FileExists(Server.MapPath(page))=true Then
    : if objFSO.FileExists(Server.MapPath(page)) <> true Then
    :
    : > See, if a page does not exist, I want it to redirect to home.asp.
    : > But, if this statement always returns true, then is means it will
    : > return true if the file exists (let's say advert.asp), so then I
    :
    : Here is what I meant about using response.write for debugging your code:
    :
    : if linkname <> "" then
    : page = linkname & ".html"
    : 'for debugging:
    : response.write "Before IF statement:<BR>"
    : response.write server.MapPath(page) & "<BR>"
    : response.write "objFSO.FileExists(server.MapPath(page)) returns "
    : response.write objFSO.FileExists(server.MapPath(page)) & "<BR>"
    : 'comment out the above lines when finished debugging
    :
    : If objFSO.FileExists(server.MapPath(page)) = false Then
    : page = "home.asp"
    : End If
    : end if
    : 'for debugging:
    : response.write "After IF statement:<BR>"
    : response.write page
    : response.end
    : 'comment out the above lines when finished debugging
    :
    : Bob Barrows
    : --
    : Microsoft MVP - ASP/ASP.NET
    : Please reply to the newsgroup. This email account is my spam trap so I
    : don't check it very often. If you must reply off-line, then remove the
    : "NO SPAM"
    :
    :
    Ok, I apologize for my ignorance, and with your help, I got this, and it
    works as well:

    if linkname <> "" then
    page = linkname & ".html"
    If NOT objFSO.FileExists(page) Then
    page = page
    else
    page = "home.asp"
    End If

    Thanx for all your help, and for being so patient with me



    --

    Kind Regards
    Rudi Ahlers
    +27 (82) 926 1689

    Greater love has no one than this, that he lay down his life for his friends
    (John 15:13).
     
    Lord Merlin, Apr 13, 2004
    #16
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Uchtman

    another objFSO question.

    Jeff Uchtman, Oct 20, 2003, in forum: ASP General
    Replies:
    3
    Views:
    133
    Ken Schaefer
    Oct 20, 2003
  2. Poppy

    FileExists FSO

    Poppy, Mar 2, 2004, in forum: ASP General
    Replies:
    3
    Views:
    137
    Evertjan.
    Mar 2, 2004
  3. Eric
    Replies:
    7
    Views:
    522
    mrbester
    Mar 3, 2005
  4. Bob
    Replies:
    1
    Views:
    333
    Ray Costanzo [MVP]
    Apr 26, 2005
  5. Joe

    FileExists on a Different Server

    Joe, Jan 14, 2009, in forum: ASP General
    Replies:
    2
    Views:
    406
Loading...

Share This Page