Skip to content
Related Articles

Related Articles

ASP Server.MapPath Method
  • Last Updated : 02 Mar, 2021

The MapPath method is used to define a relative virtual path for a physical directory on the server.       

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

Syntax:

Server.MapPath(path)                                                               

  Parameter Value:

  • path: It stores a string value that defines the relative or virtual path to map to a physical directory. If the path starts with either a forward slash(/) or backward slash(\) the MapPath Method returns a path as if the path is a full virtual path. If the path doesn’t start with a slash, the MapPath Method returns a path relative to a directory of the .asp file being processed.

Example Code: Below code that demonstrates the use of the Server.MapPath Method.

<%
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
My Personal Notes arrow_drop_up
Recommended Articles
Page :