Server.MapPath()获取绝对路径

1.    Server.MapPath("/")  应用程序根目录所在的位置 如

C:Inetpubwwwroot

2.Server.MapPath("./")  表示所在页面的当前目录 
      注:等价于Server.MapPath("")  返回 Server.MapPath("")所在页面的物理文件路径
      3.Server.MapPath("../")表示上一级目录 
      4.Server.MapPath("~/")表示当前应用级程序的目录,如果是根目录,就是根目录,如果是虚拟目录,就是虚拟目录所在的位置如:   

C:InetpubwwwrootExample
     注:等效于Server.MapPath("~"),即相对路径

Java代码 :
string filename=Server.MapPath("./") + @"Web.config";   
string filename=Server.MapPath("./") + "/Web.config";   
string filename=Server.MapPath("") + @"Web.config"  

string filename=Server.MapPath("./") + @"Web.config";

string filename=Server.MapPath("./") + "/Web.config";

string filename=Server.MapPath("") + @"Web.config"

string Server.MapPath(string path)
��返回与Web服务器上的指定虚拟路径相对应的物理文件路径。�

Html代码 
<%=Server.MapPath(Request.ServerVariables["PATH_INFO"])%>  
  
�<%= Server.MapPath("/")%>  
��<%= Server.MapPath("")%>  
��<%=Server.MapPath(".")%>  
  
��<%= Server.MapPath("../")%>  
��<%= Server.MapPath("..")%>��  

<%=Server.MapPath(Request.ServerVariables["PATH_INFO"])%> 

��<%= Server.MapPath("/")%>

��<%= Server.MapPath("")%>

��<%=Server.MapPath(".")%> 

��<%= Server.MapPath("../")%>

��<%= Server.MapPath("..")%>�� 
�以上的代码在http://localhost/EnglishClub/manage/WebForm1.aspx页面
��运行结果:
��C:InetpubwwwrootEnglishClubmanageWebForm1.aspx
��
��C:Inetpubwwwroot
��C:InetpubwwwrootEnglishClubmanage
��C:InetpubwwwrootEnglishClubmanage
��
��C:InetpubwwwrootEnglishClub
��C:InetpubwwwrootEnglishClub

原文地址:https://www.cnblogs.com/donchen/p/3944728.html