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.
There are many ways to get executable path, which one we should use it depends on our needs here is a link which discuss different methods.
Different ways to get Application Executable Path
If you are looking for a .NET Core compatible way, use
This was introduced in .NET Framework 4.6 and .NET Core 1.0 (and .NET Standard 1.3). See: AppContext.BaseDirectory Property.
According to this page,
you can use this one instead.
I have used this code and get the solution.
You can simply add to your project references
System.Windows.Forms
and then use theSystem.Windows.Forms.Application.StartupPath
as usual .So, not need for more complicated methods or using the reflection.
System.Reflection.Assembly.GetExecutingAssembly()
.Location
1Combine that with
System.IO.Path.GetDirectoryName
if all you want is the directory.