轉貼來源:http://www.AllenKuo.com.tw ( 格子樑 | 艾倫 郭 )

若在 asp.net 裡想取得根目錄的實體位置,可以寫成
string path = Server.MapPath(“/”);

若在 Windows Forms可以寫成
string path = Application.StartupPath ;

若在 Console Application 可以寫成 
string path=System.AppDomain.CurrentDomain.BaseDirectory;

如果您想寫一支 dll 專案,供上述專案類型參考並叫用, 而您想在 dll 取得目前該專案的根目錄, 則可以寫成
string path=System.AppDomain.CurrentDomain.BaseDirectory;

是可以在上述三種專案裡同時正確執行

net 裡想取得根目錄的實體位置,可以寫成
string path = Server.MapPath(“/”);

若在 Windows Forms可以寫成
string path = Application.StartupPath ;

若在 Console Application 可以寫成 
string path=System.AppDomain.CurrentDomain.BaseDirectory;

如果您想寫一支 dll 專案,供上述專案類型參考並叫用, 而您想在 dll 取得目前該專案的根目錄, 則可以寫成
string path=System.AppDomain.CurrentDomain.BaseDirectory;

是可以在上述三種專案裡同時正確執行