C#獲取項(xiàng)目程序及運(yùn)行路徑的方 1.asp.net webform用“Request.PhysicalApplicationPath獲取站點(diǎn)所在虛擬目錄的物理路徑,,最后包含“\”,; 2.c# winform用 A:“Application.StartupPath”:獲取當(dāng)前應(yīng)用程序所在目錄的路徑,最后不包含“\”,; B:“Application.ExecutablePath ”:獲取當(dāng)前應(yīng)用程序文件的路徑,,包含文件的名稱,; C:“AppDomain.CurrentDomain.BaseDirectory”:獲取當(dāng)前應(yīng)用程序所在目錄的路徑,,最后包含“\”,; D:“System.Threading.Thread.GetDomain().BaseDirectory”:獲取當(dāng)前應(yīng)用程序所在目錄的路徑,最后包含“\”,; E:“Environment.CurrentDirectory”:獲取當(dāng)前應(yīng)用程序的路徑,,最后不包含“\”,; F:“System.IO.Directory.GetCurrentDirectory”:獲取當(dāng)前應(yīng)用程序的路徑,最后不包含“\”,; 3.c# windows service服務(wù)中用“AppDomain.CurrentDomain.BaseDirectory”或“System.Threading.Thread.GetDomain().BaseDirectory”,; 用“Environment.CurrentDirectory”和“System.IO.Directory.GetCurrentDirectory”將得到“ system32”目錄的路徑; 如果要使用“Application.StartupPath”或“Application.ExecutablePath ”,,需要手動(dòng)添加對(duì)“System.Windows.Forms.dll ”的引用,,并在程序開(kāi)頭用“using System.Windows.Forms”聲明該引用; 4.在卸載程序獲取系統(tǒng)安裝的目錄: System.Reflection.Assembly curPath = System.Reflection.Assembly.GetExecutingAssembly(); string path=curPath.Location;//得到安裝程序類SetupLibrary文件的路徑,,獲取這個(gè)文件路徑所在的目錄即得到安裝程序的目錄; 一、獲取當(dāng)前文件的路徑 System.Environment.SystemDirectory ;C:/windows/system32目錄 1,、System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName=D:\Visual Studio Projects\MyApplication\LifeAssistant\bin\Debug\LifeAssistant.exe 2,、System.Environment.CurrentDirectory=D:\Visual Studio Projects\MyApplication\LifeAssistant\bin\Debug 3、System.IO.Directory.GetCurrentDirectory()=D:\Visual Studio Projects\MyApplication\LifeAssistant\bin\Debug Request.PhysicalApplicationPath獲取站點(diǎn)所在虛擬目錄的物理路徑,,最后包含“\”,; Application.StartupPath”:獲取當(dāng)前應(yīng)用程序所在目錄的路徑,最后不包含“\”; Application.ExecutablePath ”:獲取當(dāng)前應(yīng)用程序文件的路徑,,包含文件的名稱,; AppDomain.CurrentDomain.BaseDirectory”:獲取當(dāng)前應(yīng)用程序所在目錄的路徑,最后包含“\”,; System.Threading.Thread.GetDomain().BaseDirectory”:獲取當(dāng)前應(yīng)用程序所在目錄的路徑,,最后包含“\”; Environment.CurrentDirectory”:獲取當(dāng)前應(yīng)用程序的路徑,,最后不包含“\”,; System.IO.Directory.GetCurrentDirectory”:獲取當(dāng)前應(yīng)用程序的路徑,最后不包含“\”,; AppDomain.CurrentDomain.BaseDirectory”或“ System.Threading.Thread.GetDomain().BaseDirectory”,; Environment.CurrentDirectory”和“ System.IO.Directory.GetCurrentDirectory”將得到“ system32”目錄的路徑; Application.StartupPath”或“ Application.ExecutablePath ”,,需要手動(dòng)添加對(duì)“System.Windows.Forms.dll ”的引用,,并在程序開(kāi)頭用“using System.Windows.Forms”聲明該引用; System.Reflection.Assembly curPath = System.Reflection.Assembly.GetExecutingAssembly(); string path=curPath.Location;//得到安裝程序類SetupLibrary文件的路徑,,獲取這個(gè)文件路徑所在的目錄即得到安裝程序的目錄; 4,、System.AppDomain.CurrentDomain.BaseDirectory=D:\Visual Studio Projects\MyApplication\LifeAssistant\bin\Debug\ 5、System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase=D:\Visual Studio Projects\MyApplication\LifeAssistant\bin\Debug\ 6,、System.Windows.Forms.Application.StartupPath=D:\Visual Studio Projects\MyApplication\LifeAssistant\bin\Debug 7,、System.Windows.Forms.Application.ExecutablePath=D:\Visual Studio Projects\MyApplication\LifeAssistant\bin\Debug\LifeAssistant.exe System.Environment.GetEnvironmentVariable("windir")=C:\WINDOWS System.Environment.GetEnvironmentVariable("INCLUDE")=C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\include\ System.Environment.GetEnvironmentVariable("TMP")=C:\DOCUME~1\zhoufoxcn\LOCALS~1\Temp System.Environment.GetEnvironmentVariable("TEMP")=C:\DOCUME~1\zhoufoxcn\LOCALS~1\Temp System.Environment.GetEnvironmentVariable("Path")=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\jdk1.5.0\bin;C:\MySQLServer5.0\bin;C:\Program Files\Symantec\pcAnywhere\;C:\Program Files\Microsoft SQL Server\80\Tools\BINN
|
|
來(lái)自: ontheroad96j47 > 《待分類》