server.mappath() parent

V

vunet.us

How to use server.mappath() parent folder correctly:

Server.MapPath("../test.asp")

Thank you for the hint.
 
V

vunet.us

MapPath
The MapPath method maps the specified relative or virtual path to the corresponding physical directory on the server.

Syntax
Server.MapPath( Path )
Parameters
Path
Specifies the relative or virtual path to map to a physical directory. If Path starts with either a forward (/) or backward slash
(\), the MapPath method returns a path as if Path is a full virtual path. If Path doesn't start with a slash, the MapPath method
returns a path relative to the directory of the .asp file being processed.
Remarks
The MapPath method does not support relative path syntax (.) or (..). For example, the following relative path, ../MyDir/MyFile.txt,
returns an error.

The MapPath method does not check whether the path it returns is valid or exists on the server.

Because the MapPath method maps a path regardless of whether the specified directories currently exist, you can use the MapPath
method to map a path to a physical directory structure, and then pass that path to a component that creates the specified directory
or file on the server.

so what would be a reasonlabe solution to check the existence of
temp.asp inside of file1.asp:

www.mysite.com/filder2/file1.asp
www.mysite.com/temp/temp/temp.asp
 
D

Daniel Crichton

so what would be a reasonlabe solution to check the existence of
temp.asp inside of file1.asp:

www.mysite.com/filder2/file1.asp
www.mysite.com/temp/temp/temp.asp

Try

sFile = Server.MapPath("/temp/temp/temp.asp")

Set oFS = Server.CreateObject("Scripting.FileSystemObject")
If oFS.FileExists(sFile) Then
'file exists
End If
Set oFS = Nothing

Of course, this isn't a perfect solution - for instance, there may be an
ISAPI pre-processor that handles incoming requests and redirects them
elsewhere based on the path, so the file /temp/temp/temp.asp might not even
reside on the same server, or in the same path structure, as
/filder2/file1.asp. Assuming a "normal" configuration, this should work
though.

Dan
 
V

vunet.us

(e-mail address removed) wrote on 3 May 2007 12:20:44 -0700:


Try

sFile = Server.MapPath("/temp/temp/temp.asp")

Set oFS = Server.CreateObject("Scripting.FileSystemObject")
If oFS.FileExists(sFile) Then
'file exists
End If
Set oFS = Nothing

Of course, this isn't a perfect solution - for instance, there may be an
ISAPI pre-processor that handles incoming requests and redirects them
elsewhere based on the path, so the file /temp/temp/temp.asp might not even
reside on the same server, or in the same path structure, as
/filder2/file1.asp. Assuming a "normal" configuration, this should work
though.

Dan

let me try. thanks a lot
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top