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 a slash, either a / or 貼, the MapPath method returns a path relative to the virtual directory. If path doesn稚 start with a slash, the MapPath method returns a path relative to the current directory, in other words, the path relative to the server variable, PATH_INFO.

Remarks

The MapPath method maps a path to a physical path on the server regardless of whether the path currently exists. Thus 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.

Examples

For the examples below, the file Data.txt is located in the directory, C:\Inetsrv\Scripts\, as is the Test.asp file that contains the following scripts.

The following example uses the server variable PATH_INFO to map the physical path of the current file. The following:

<%= server.mappath(Request.ServerVariables("PATH_INFO"))%><BR>
 

produces the output:

c:\inetsrv\scripts\test.asp<BR>
 

Because the path parameter in the following examples do not start with a slash character, they are mapped relative to the current directory, in this case C:\Inetsrv\Scripts\. The following examples:

<%= server.mappath("data.txt")%><BR>
<%= server.mappath("scripts/data.txt")%><BR>

produce the following ouput:

c:\inetsrv\scripts\data.txt<BR>
c:\inetsrv\scripts\scripts\data.txt<BR>
 

The next two examples use the slash characters to specify that the path returned should be looked up relative to the virtual root. The following examples:

<%= server.mappath("/scripts/data.txt")%><BR>
<%= server.mappath("\scripts")%><BR>
 

produce the following output:

c:\inetsrv\scripts\data.txt<BR>
c:\inetsrv\scripts<BR>
 

The following examples demonstrate how you can use either a forward slash / or a backslash 貼 to return the physical path to the current directory. The following examples:

<%= server.mappath("/")%><BR>
<%= server.mappath("\")%><BR>
 

produce the following output:

c:\inetsrv\scripts<BR>
c:\inetsrv\scripts<BR>
 

Applies To

Server Object