objFSO.FileExists not working?????

R

Rudi Ahlers

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).
 
S

Steven Burn

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)
 
B

Bob Barrows

Rudi said:
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
 
L

Lord Merlin

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).
Rudi said:
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
 
E

Egbert Nierop \(MVP for IIS\)

Rudi Ahlers said:
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"
 
L

Lord Merlin

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).
message
Rudi Ahlers said:
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"
 
E

Egbert Nierop \(MVP for IIS\)

Lord Merlin said:
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.
 
R

Roland Hall

in message : 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
 
L

Lord Merlin

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).
in message : 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
 
B

Bob Barrows

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

Lord Merlin

--

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).
: 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).
: > : > "Rudi Ahlers" wrote in message : >> 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
 
R

Roland Hall

in message : 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
 
L

Lord Merlin

: "Lord Merlin" wrote in message : : 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).
 
R

Roland Hall

in message : : : "Lord Merlin" wrote in message : : : 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.
 
B

Bob Barrows

Roland said:
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)) said:
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
 
L

Lord Merlin

: 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).
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top