C# 獲取可執行文件路徑的上上級目錄的方法

1、

DirectoryInfo di = new DirectoryInfo(string.Format(@"{0}..\..\", Application.StartupPath));

di.FullName

就是你想要的

..\有幾個就是往回退幾層

2、

DirectoryInfo info = new DirectoryInfo(Application.StartupPath);

String path = info.Parent.Parent.FullName;

 

3、

 

string WantedPath = Application.StartupPath.Substring(0,Application.StartupPath.LastIndexOf(@"\"));

4.

 string filePath = AppDomain.CurrentDomain.BaseDirectory + @"\..\測試\1.xml";  

實際路徑是(AppDomain.CurrentDomain.BaseDirectory的上一層)\測試\1.xml

退幾層就是幾個..\

 

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