Product Home Page | Developer Site | Version | |
For the examples below, the data.txt and test.asp files are located in the c:\inetpub\wwwroot\script directory. The test.asp file contains scripts. The c:\inetpub\wwwroot directory is set as the server's home directory.
The following example uses the server variable PATH_INFO to map the physical path to the current file:
<%= server.mappath(Request.ServerVariables("PATH_INFO"))%>
<BR>
This script produces the following:
c:\inetpub\wwwroot\script\test.asp<BR>
Because the path parameters in the following examples do not start with a slash character, they are mapped relative to the current directory, in this case c:\inetpub\wwwroot\script.
<%= server.mappath("data.txt")%><BR>
<%= server.mappath("script/data.txt")%><BR>
This script outputs the following:
c:\inetpub\wwwroot\script\data.txt<BR>
c:\inetpub\wwwroot\script\script\data.txt<BR>
The next two scripts use the slash characters to specify that the paths returned should be looked up as complete virtual paths on the server:
<%= server.mappath("/script/data.txt")%><BR>
<%= server.mappath("\script")%><BR>
This script outputs the following:
c:\inetpub\script\data.txt<BR>
c:\inetpub\script<BR>
The following examples demonstrate how you can use either a forward slash or a backslash to return the physical path to the home directory. The following script:
<%= server.mappath("/")%><BR>
<%= server.mappath("\")%><BR>
produces the following output:
c:\inetpub\wwwroot<BR>
c:\inetpub\wwwroot<BR>
Copyright © 2003 Sun Microsystems, Inc. All rights reserved.