How can I get the application's path in a .NET console application?

后端 未结 27 1403
甜味超标
甜味超标 2020-11-21 11:11

How do I find the application\'s path in a console application?

In Windows Forms, I can use Application.StartupPath to find the current path, but this d

相关标签:
27条回答
  • 2020-11-21 12:09

    in VB.net

    My.Application.Info.DirectoryPath
    

    works for me (Application Type: Class Library). Not sure about C#... Returns the path w/o Filename as string

    0 讨论(0)
  • 2020-11-21 12:14

    I have used

    System.AppDomain.CurrentDomain.BaseDirectory
    

    when I want to find a path relative to an applications folder. This works for both ASP.Net and winform applications. It also does not require any reference to System.Web assemblies.

    0 讨论(0)
  • 2020-11-21 12:14

    Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName) Is the only one that has worked for me in every case I have tried.

    0 讨论(0)
提交回复
热议问题