Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

ASP MapPath Method

ASP MapPath Method


Server Object Reference Complete Server Object Reference Manual


The MapPath method maps a specified path to the corresponding physical path on the server.

**Note:** This method cannot be used in Session.OnEnd or Application.OnEnd.

Syntax

Server.MapPath(path)

Parameters Description
path Required. A relative or absolute path to map to a physical path. If the argument begins with / or \, the full virtual path is returned. If it does not begin with / or \, the path returned is relative to the .asp file being processed.

Example

Example 1

For example, the file test.asp is located in C:\Inetpub\wwwroot\Script.

The file Test.asp (located in C:\Inetpub\wwwroot\Script) contains the following code:

<%

response.write(Server.MapPath("test.html") & "
")

response.write(Server.MapPath("script/test.html") & "
")

response.write(Server.MapPath("/script/test.html") & "
")

response.write(Server.MapPath("script") & "
")

response.write(Server.MapPath("/") & "
")

response.write(Server.MapPath("") & "
")

%>

Output:

c:inetpubwwwrootscripttest.html

c:inetpubwwwrootscriptscripttest.html

c:inetpubwwwrootscripttest.html

c:inetpubwwwrootscript

c:inetpubwwwroot

c:inetpubwwwroot

Example 2

How to use a relative path to return the relative physical path to the page being viewed in the browser:

<%

response.write(Server.MapPath("../"))

%>

or:

<%

response.write(Server.MapPath(".."))

%>


Server Object Reference Complete Server Object Reference Manual