Executable directory where application is running from?

前端 未结 6 1782
无人共我
无人共我 2020-12-01 04:46

I need to get the path (not the executable) where my application is running from:

System.AppDomain.CurrentDomain.BaseDirectory()

When I run

6条回答
  •  庸人自扰
    2020-12-01 05:13

    I needed to know this and came here, before I remembered the Environment class.

    In case anyone else had this issue, just use this: Environment.CurrentDirectory.

    Example:

    Dim dataDirectory As String = String.Format("{0}\Data\", Environment.CurrentDirectory)
    

    When run from Visual Studio in debug mode yeilds:

    C:\Development\solution folder\application folder\bin\debug
    

    This is the exact behaviour I needed, and its simple and straightforward enough.

提交回复
热议问题