您的位置:首页 > 编程语言 > C#

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

2012-08-22 10:45 633 查看
整理记录,以备自己查询用。

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)\
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: