Sunday, 14 April 2013

How to use server.mappath

How to use server.mappath

Server.MapPath specifies the relative or virtual path to map to a physical directory.

Server.MapPath(".") returns the current physical directory of the file (e.g. aspx) being executed
Server.MapPath("..") returns the parent directory
Server.MapPath("~") returns the physical path to the root of the application
Server.MapPath("/") returns the physical path to the root of the domain name (is not necessarily the same as the root of the application)
An example:

Let's say you pointed a web site application ( to

and installed your application (sub web as virtual directory in IIS, marked as application) in

For example, if you call Server.MapPath in following request:

Server.MapPath(".") returns D:\WebApps\category\products
Server.MapPath("..") returns D:\WebApps\category
Server.MapPath("~") returns D:\WebApps\category
Server.MapPath("/") returns C:\Inetpub\wwwroot
Server.MapPath("/shop") returns D:\WebApps\shop