PROWAREtech

articles » current » dot-net » executable-path

.NET: Retrieve the Executable's Path and Directory

How to find the .NET executable's path and directory using the C# programming language.

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

// NOTE: Get the full name path of the executable file
string exeFullName = System.Reflection.Assembly.GetExecutingAssembly().Location;
// NOTE: 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.


This site uses cookies. Cookies are simple text files stored on the user's computer. They are used for adding features and security to this site. Read the privacy policy.
CLOSE