Server.MapPath method Returns the physical file path and takes input parameter as virtual path.
- Server.MapPath(".") will return the current physical directory of the file (e.g. aspx or view) being executed
- Server.MapPath("..") will return the parent directory to the current physical directory of the file (e.g. aspx or view) being executed
- Server.MapPath("~") will return the physical path to the root of the application
- Server.MapPath("/") will return the physical path to the root of the domain name (is not necessarily the same as the root of the application)
For An example:
Suppose you pointed a web site application (https://www.myexample.com/) to
C:\Inetpub\wwwroot
and installed your shop application (sub web as virtual directory in IIS, marked as application) in
D:\MyWebApps\shop
For example, if you call Server.MapPath in following request:
https://www.myexample.com/shop/products/GetMyProduct.aspx?id=2342
then:
- Server.MapPath(".") will return D:\MyWebApps\shop\products
- Server.MapPath("..") will return D:\MyWebApps\shop
- Server.MapPath("~") will return D:\MyWebApps\shop
- Server.MapPath("/") will return C:\Inetpub\wwwroot
- Server.MapPath("/shop") will return D:\MyWebApps\shop
- Server.MapPath(null) or Server.MapPath("") will return D:\MyWebApps\shop\products
Posted On:
02-May-2016 00:36