C#中獲取路徑的幾種方法

1.    在.Net中web開發時

(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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章