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 doesn't seem to be available in a console application.
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 doesn't seem to be available in a console application.
Try this simple line of code:
Here is a reliable solution that works with 32bit and 64bit applications.
Add these references:
Add this method to your project:
Now use it like so:
Notice that if you know the id of the process, then this method will return the corresponding ExecutePath.
Extra, for those interested:
...will give you an array of all the currently running processes, and...
...will give you the current process, along with their information e.g. Id, etc. and also limited control e.g. Kill, etc.*
You may be looking to do this:
I mean, why not a p/invoke method?
You would use it just like the Application.StartupPath:
You can use the following code to get the current application directory.
in VB.net
works for me (Application Type: Class Library). Not sure about C#... Returns the path w/o Filename as string