Windows Form和Web Form通用的當前應用程序所在路徑獲取方法
System.AppDomain.CurrentDomain.BaseDirectory
或者
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase
下面是幾個獲取當前應用程序所在路徑方法的執行結果:
Web Form
System.Environment.CurrentDirectory:
C:Program FilesMicrosoft Visual Studio 9.0Common7IDE
System.AppDomain.CurrentDomain.BaseDirectory:
F:PraticeAppCurrentRunPathWebFormPath
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase:
F:PraticeAppCurrentRunPathWebFormPath
System.IO.Directory.GetCurrentDirectory():
C:Program FilesMicrosoft Visual Studio 9.0Common7IDE
Windows Form
System.Environment.CurrentDirectory:
F:PraticeAppCurrentRunPathWindowsFormsPathinDebug
System.AppDomain.CurrentDomain.BaseDirectory:
F:PraticeAppCurrentRunPathWindowsFormsPathinDebug
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase:
F:PraticeAppCurrentRunPathWindowsFormsPathinDebug
System.Windows.Forms.Application.StartupPath:
F:PraticeAppCurrentRunPathWindowsFormsPathinDebug
System.IO.Directory.GetCurrentDirectory():
F:PraticeAppCurrentRunPathWindowsFormsPathinDebug
參考文檔:
C#獲取當前程序運行路徑的方法集合
http://www.cnblogs.com/cocoulong/archive/2010/01/30/1660119.html
c#獲取當前應用程序所在路徑
http://www.cnblogs.com/baaigeini/archive/2009/03/09/1407078.html