C#中得到程序当前工作目录和执行目录的一些方法

整理记录,以备自己查询用。

1、获取模块的完整路径

  • System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName

  如:E:\WindowsFormsApplication\bin\Release(Debug)\WindowsFormsApplication.vshost.exe

  • System.Windows.Forms.Application.ExecutablePath

  如:E:\WindowsFormsApplication\bin\Release(Debug)\WindowsFormsApplication.EXE

2、获取当前目录的完全限定目录(应用程序的可执行文件的路径)

  • System.Environment.CurrentDirectory 

  如:E:\WindowsFormsApplication\bin\Release(Debug)

  • System.Windows.Forms.Application.StartupPath

  如:E:\WindowsFormsApplication\bin\Release(Debug)

  • System.IO.Directory.GetCurrentDirectory()  

  如:E:\WindowsFormsApplication\bin\Release(Debug)

3、获取程序的基目录

  • System.AppDomain.CurrentDomain.BaseDirectory

  如:E:\WindowsFormsApplication\bin\Release(Debug)\

  • System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase     

  如:E:\WindowsFormsApplication\bin\Release(Debug)\

posted on 2012-08-22 10:45  岁月静好  阅读(761)  评论(0编辑  收藏  举报

导航