前一段时间写代码时经常遇到获取路径问题,总是感觉有点乱,于是就总结了下,大家若有需要可以参考

1.    .Netweb开发时

(1)  ~/runat=server的控件中会自动被解析为Request.ApplicationPath的值,是当前应用程序的目录

 

~/userCommunity/index.aspx则对应为/HENU.RCenter.Internal/UserCommunity

2 ./表示当前目录

3../表示上一层目录 UserCommunity文件夹下的文件中可以以:../module/来访问module中的文件

2 获取当前请求页面的路径:Request.FilePath

3 获取项目下的文件路径:

string path=AppDomain. CurrentDomain .SetUpInformation.ApplicationBase+文件夹+文件

如获取项目下的temp文件夹下文件的路径

可以用:string savePath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "temp" + @"\" + filename

4 Server.MapPath用法:

若在项目下Content文件夹下的UserInfoManager.aspx代码中写如下路径

this.tempPath = Server.MapPath("UploadResourceImage\\");

则返回 D:\wxm\练习\Content\UploadResourceImage