The
Parameters
用法:
1.Server.MapPath("/")
2.Server.MapPath("./")
3.Server.MapPath("../")表示上一级目录
4.Server.MapPath("~/")表示当前应用级程序的目录,如果是根目录,就是根目录,如果是虚拟目录,就是虚拟目录所在的位置
注:等效于Server.MapPath("~")。
不知道是否正确,研究中......
另:以下几句等效
string
string
string
附一例子:修改web.config的某一节点的属性值
<%=Server.MapPath(Request.ServerVariables["PATH_INFO"])%>
<%= Server.MapPath("/")%>
<%= Server.MapPath("")%>
<%=Server.MapPath(".")%>
<%= Server.MapPath("../")%>
<%= Server.MapPath("..")%>
以上的代码在http://localhost/EnglishClub/manage/WebForm1.aspx页面
运行结果:
C:/Inetpub/wwwroot/EnglishClub/manage/WebForm1.aspx
C:/Inetpub/wwwroot/
C:/Inetpub/wwwroot/EnglishClub/manage
C:/Inetpub/wwwroot/EnglishClub/manage
C:/Inetpub/wwwroot/EnglishClub/
C:/Inetpub/wwwroot/EnglishClub
string filename ="20059595157517.jpg";
string str=HttpContext.Current.Server.MapPath("file")+filename;
//取得filename当前路径,其中file位于主文件夹下。