ASP MapPath Attribute
Definition and Usage
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. Maps a relative or absolute path to the physical path. If the parameter starts with / or \, it returns the full virtual path. If the parameter does not start with / or \, it returns the path relative to the .asp file being processed. |
Example
Example 1
For example, the file test.asp is located at C:\Inetpub\wwwroot\Script.
The file Test.asp (located at C:\Inetpub\wwwroot\Script) contains the following code:
<% response.write(Server.MapPath("test.asp") & "<br />") response.write(Server.MapPath("script/test.asp") & "<br />") response.write(Server.MapPath("/script/test.asp") & "<br />") response.write(Server.MapPath("\script") & "<br />") response.write(Server.MapPath("/") & "<br />") response.write(Server.MapPath("\") & "<br />") %>
Output:
c:\inetpub\wwwroot\script\test.asp c:\inetpub\wwwroot\script\script\test.asp c:\inetpub\wwwroot\script\test.asp c:\inetpub\wwwroot\script c:\inetpub\wwwroot c:\inetpub\wwwroot
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("..\")) %>