Reader Level:
Articles

Server.MapPath() in ASP.Net

By Abhimanyu K Vatsa on June 14, 2010
This article will demonstrate how to use and why to use Server.MapPath() in ASP.Net web applications.
  • 1
  • 0
  • 54699
Download Files:
 

Introduction and Demonstration

Many times we need to know the full path of remote server where we are hosting or the exact location of file but if we don't how we can't. Actually we have MapPath method which maps the specified relative or virtual path to the corresponding physical directory on the web server. Usually any web server never allows to access in any path if we don't have proper permission. Even we can't list the directories or file as we list in DOS like

server1.gif

As in above picture, we can list on web server via remotely without proper permission because of security reason. But we can see the full path where the particular page exists as in example given below.

server2.gif

In above example, coded (given below) file is being hosted at remote server and it is displaying (mapping) the physical location (path) of my hosting server. Here is my coding I have used.

protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(Server.MapPath("."));
        Response.Write("<br>");
        Response.Write(Server.MapPath(""));
        Response.Write("<br>");
        Response.Write(Server.MapPath("~"));
    }

HAVE A HAPPY CODING!
 

Abhimanyu K Vatsa

Microsoft MVP | Author | IT Faculty | Student of M.Tech. IT | Blogs at ITORIAN.COM

Personal Blog: http://www.itorian.com
COMMENT USING

Trending up