C#获取工作目录和执行目录的方法

1、获取工作目录
(1)、System.Environment.CurrentDirectory
获取或设置当前目录(该进程从中启动的目录)的完全限定目录。
(2)、System.IO.Directory.GetCurrentDirectory()
获取应用程序的当前工作目录。
(3)、System.AppDomain.CurrentDomain.BaseDirectory
获取基目录。它由程序集冲突解决程序用来探测程序集。
(4)、System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase
获取或设置包括该应用程序的目录的名称。
(5)、System.Windows.Forms.Application.StartupPath
获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。
2、获取执行目录
(1)、System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
获取模块的完整路径。
(2)、System.Windows.Forms.Application.ExecutablePath
获取启动了应用程序的可执行文件的路径及文件名,效果有时和1一样。

你可能感兴趣的:(C#)