Server.MapPath with usage of . , .. , ~ and / Characters in ASP.NET

Published on October 2, 2014 by admin

Filed under ASP.NET

Last modified October 2, 2014

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 1 (1 votes)

This article have been viewed 19268 times

When using Server.MapPath in ASP.NET, the developers can specify the characters as shown below.

var path1 = Server.MapPath(“.”)
var path2 = Server.MapPath(“..”)
var path3 = Server.MapPath(“~”)
var path4 = Server.MapPath(“/”)

What is the difference between the above methods ?

Assume that the website is installed in the path D:\WebApplications\Abundantcode and the root of the IIS is C:\Inetpub\wwwroot and assume that the current page is

The path1 will contain D:\WebApplications\Abundantcode\popularposts which is the current physical directory of the file

Path 2 will contain D:\WebApplications\Abundantcode\ which is the parent directory

Path 3 will contain D:\WebApplications\Abundantcode\ which is the physical path of the root of the application.

Path 4 will contain C:\Inetpub\wwwroot which is root of the domain name.

Leave a Comment


You might be Interested in these Posts

How to read connection string from web.config in ASP.NET and C# ?

Here's a sample code snippet demonstrating how to get the connection string from your ASP.NET

How to return Json instead of XML in ASP.NET Web API ?

When you make a call to the ASP.NET Web API action method and notice this in Google Chrome browser ,...

How to Add Web API to existing ASP.NET Web Forms Project ?

In one of the previous posts , we saw how to add the WebAPI to the existing ASP.NET MVC project. Wel...