在C#中,咱們有如下幾種方式獲取程序當前目錄:spa
Console.WriteLine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
Console.WriteLine(System.AppDomain.CurrentDomain.BaseDirectory);
Console.WriteLine(System.Environment.CurrentDirectory);
Console.WriteLine(System.IO.Directory.GetCurrentDirectory());
Console.WriteLine(Environment.CurrentDirectory);
輸出:code
D:\MyTool\MyWorkRelated\C#_Tool\Defect Process Tool\DefectExcelProcesTool\DefectExcelProcesTool\bin\Debug
D:\MyTool\MyWorkRelated\C#_Tool\Defect Process Tool\DefectExcelProcesTool\DefectExcelProcesTool\bin\Debug\
D:\MyTool\MyWorkRelated\C#_Tool\Defect Process Tool\DefectExcelProcesTool\DefectExcelProcesTool\bin\Debug
D:\MyTool\MyWorkRelated\C#_Tool\Defect Process Tool\DefectExcelProcesTool\DefectExcelProcesTool\bin\Debug
D:\MyTool\MyWorkRelated\C#_Tool\Defect Process Tool\DefectExcelProcesTool\DefectExcelProcesTool\bin\Debugblog
親測能夠代碼正確。it