Server.MapPath specifies the relative or virtual path to map to a physical directory.
Server.MapPath(".")
1 returns the current physical directory of the file (e.g. aspx) being executedServer.MapPath("..")
returns the parent directoryServer.MapPath("~")
returns the physical path to the root of the applicationServer.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 (http://www.example.com/) to
C:\Inetpub\wwwroot
and installed your shop application (sub web as virtual directory in IIS, marked as application) in
D:\WebApps\shop
For example, if you call Server.MapPath in following request:
http://www.example.com/shop/products/GetProduct.aspx?id=2342
then:
Server.MapPath(".")
1 returnsD:\WebApps\shop\products
Server.MapPath("..")
returnsD:\WebApps\shop
Server.MapPath("~")
returnsD:\WebApps\shop
Server.MapPath("/")
returnsC:\Inetpub\wwwroot
Server.MapPath("/shop")
returnsD:\WebApps\shop
If Path starts with either a forward (
/
) or backward slash (\
), the MapPath method returns a path as if Path were a full, virtual path.
If Path doesn't start with a slash, the MapPath method returns a path relative to the directory of the request being processed.
--reference stackkoverflow article.