1。获得站点里文件的地址,一般做为输出用
string strDir = Request.ApplicationPath+@"/";
if (strDir == @"//") strDir = @"/";
Response.Write(strDir+"index.aspx"); //输出了当前站点根目录下的index.aspx文件
2。访问站点里的文件
Response.Redirect(@"~/index.aspx"); //访问了当前站点根目录下的index.aspx文件
3。上传文件时保存的地址
Server.MapPath(""); //和Server.MapPath("/")有很大的区别
1.Server.MapPath("/") 应用程序根目录所在的位置 如 C:/Inetpub/wwwroot/
2.Server.MapPath("./") 表示所在页面的当前目录
注:等价于Server.MapPath("") 返回 Server.MapPath("")所在页面的物理文件路径
3.Server.MapPath("../")表示上一级目录
4.Server.MapPath("~/")表示当前应用级程序的目录,如果是根目录,就是根目录,如果是虚拟目录,就是虚拟目录所在的位置如:C:/Inetpub/wwwroot/Example/
注:等效于Server.MapPath("~")。
appl_path=request.servervariables("APPL_PHYSICAL_PATH")'取得站点绝对路径
post_path=request.servervariables("path_translated")'取各请求的文件的绝对路径
ss=split(post_path,"/")
post_path=replace(post_path,ss(ubound(ss)),"")'去掉文件名
str=replace(post_path,appl_path,"")&"/"'替换掉相同的
ss=split(str,"/")
foderpath="/"&ss(0)&"/"
foderpath=replace(foderpath,"//","/")