Server.MapPath

Server.MapPath is a function that takes one argument, a virtual path on the Web server, and returns the corresponding physical path. This function can be used in a number of ways. First, you can use it to obtain the physical path of a particular web page. For example: C# string strFilePath; strFilePath = Server.MapPath("/WebApp/myWebPage.aspx"); You also can use this method to obtain the physical path of a particular directory. For example: C# //current directory string strCurrDir = Server.MapPath(""); //parent directory string strParentDir = Server.MapPath(".."); //root directory string strRootDir = Server.MapPath("/"); Whether you use backslahed (\) or forward slashes (/), it is same in this function. If you do not put a forward or backward slash at the beginning of the string passed into Server.MapPath, the current directory that the ASP page is being executed is used as the base for the physical path. Else, the root physical path is used as the base for the physical path. For example: C# string strFilePath1 = Server.MapPath("someXmlFile.xml"); string strFilePath2 = Server.MapPath("/someXmlFile.xml");

No comments:

Post a Comment