方法一:
//獲取當前項目的路徑
System.AppDomain.CurrentDomain.BaseDirectory.ToString(); // 得到的是當前項目的根目錄
取的值:F://Project//System2.0//SystemForm//
方法二:
//獲取當前項目的路徑
//Server對象在頁面中使用
string path=Server.MapPath(".");
取的值:F://Project//System2.0//SystemForm//secure
//獲取當前項目的路徑
System.AppDomain.CurrentDomain.BaseDirectory.ToString(); // 得到的是當前項目的根目錄
取的值:F://Project//System2.0//SystemForm//
方法二:
//獲取當前項目的路徑
//Server對象在頁面中使用
string path=Server.MapPath(".");
取的值:F://Project//System2.0//SystemForm//secure
C# 獲取當前項目路徑
//獲取和設置當前目錄(即該進程從中啟動的目錄)的完全限定路徑。
string str = System.Environment.CurrentDirectory;
//result: X:/xxx/xxx (.exe文件所在的目錄)
同樣是C# 語言,在不同的項目里,有不同的結果。
在web項目中用,System,Environment.CurrentDirectory得到的是VS的路徑。但是在winform項目里,得到的是當前項目的debug路徑。