Get the .NET Executable Path and Directory

See related: .NET examples

Find the executable's path and its directory by using System.Reflection.Assembly.GetExecutingAssembly().Location. This will return the path to the executable.

// Get the full name path of the executable file
string exeFullName = System.Reflection.Assembly.GetExecutingAssembly().Location;
// Get the exe's directory
string dirFullName = System.IO.Path.GetDirectoryName(exeFullName); // NOTE: this will be the directory of the executable which will not be IWebHostEnvironment.ContentRootPath when debugging in Visual Studio

Now use System.IO.Path.Combine() to work in the executable's directory regardless of the platform.


Cookies are simple text files stored on the user's computer. They are used for adding features and security to this site.
OK