-2

I'm looking to create a console application in C# that can be added to the system path. So of course it will need to operate within the working directory. But I will have public key files installed in the same directory as the executable, so I will need to get the installed directory as well. How can I do this?

Clarification: In a C# console application, I want to be able to access both the working directory and the directory where the EXE file is. These are different directories. I know how to get the former, I need to know how to get the latter.

Jordan
  • 9,642
  • 10
  • 71
  • 141
  • 2
    Application.ExecutablePath from here is probably what you're after. https://stackoverflow.com/questions/15653921/get-current-folder-path – Ryan Thomas Dec 23 '19 at 13:54
  • Does this answer your question? [Get current folder path](https://stackoverflow.com/questions/15653921/get-current-folder-path) – EdChum Dec 23 '19 at 14:21

2 Answers2

4

You can use:

  • AppDomain.CurrentDomain.BaseDirectory to get the directory where your .exe and .dll files are supposed to be (usually the directory that contains your .exe file)This is probably what you need.
  • Environment.CurrentDirectory to get the path that the system shell runs your program in.
  • Assembly.GetEntryAssembly().GetName().CodeBase or Assembly.GetEntryAssembly().Location to get the exact path to your .exe file.
Dmitry Arestov
  • 1,427
  • 12
  • 24
0

So this works: System.Reflection.Assembly.GetEntryAssembly().Location

Jordan
  • 9,642
  • 10
  • 71
  • 141