ASP MapPathMethod
Complete Server Object Reference
The MapPath method maps the specified path to the corresponding physical path on the server.
Note:This method cannot be used in Session.OnEnd and Application.OnEnd.
Syntax
Server.MapPath(path)
| Parameter | Description |
|---|---|
| path | Required. The relative or absolute path to map to a physical path. If the parameter starts with / or \, a complete virtual path is returned. If the parameter does not start with / or \, the path relative to the .asp file being processed is returned. |
Examples
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") & "<br>")
response.write(Server.MapPath("script/test.html") & "<br>")
response.write(Server.MapPath("/script/test.html") & "<br>")
response.write(Server.MapPath("script") & "<br>")
response.write(Server.MapPath("/") & "<br>")
response.write(Server.MapPath("") & "<br>")
%>
Output:
c:inetpubwwwrootscripttest.html
c:inetpubwwwrootscriptscripttest.html
c:inetpubwwwrootscripttest.html
c:inetpubwwwrootscript
c:inetpubwwwroot
c:inetpubwwwroot
response.write(Server.MapPath("test.html") & "<br>")
response.write(Server.MapPath("script/test.html") & "<br>")
response.write(Server.MapPath("/script/test.html") & "<br>")
response.write(Server.MapPath("script") & "<br>")
response.write(Server.MapPath("/") & "<br>")
response.write(Server.MapPath("") & "<br>")
%>
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(".."))
%>
response.write(Server.MapPath("../"))
%>
Or:
<%
response.write(Server.MapPath(".."))
%>
Complete Server Object Reference Other Extensions