How to get the Current Executable’s path in C#

In this post we will learn HOW TO GET THE CURRENT EXECUTABLE’S PATH IN C#. Most of the time while programming we need this path.   

Additionally, the current folder is essential to reach settings, database, images, or resource files that are located in the identical directory as the presently operating C# executable file of your application. Numerous choices exist to locate the current executable path in C#. Nevertheless, I have discovered one that operates effectively for both C# .NET Console Applications and C# Windows Forms Applications. Let check out the code below.

  //You will get full name path of the executable file:
 string strExeFilePath = System.Reflection.Assembly.GetExecutingAssembly().Location;

  //Get full name of folder in which we have executable file:
  string strWorkPath = System.IO.Path.GetDirectoryName(strExeFilePath);


Kindly exercise caution while saving the configurations in the Program Files directory. This directory is safeguarded by the Windows security protocol for accounts without administrative privileges. The settings files are automatically rerouted to the corresponding folder inside the “AppData” directory for user accounts. Therefore, if the user utilizes the program twice, once with the admin account and the other time with the user account, two separate settings files may be generated, resulting in perplexity/confusion. Hence, it is advisable to use exclusive folders for storing the settings. As a reliable software developer, you would undoubtedly desire your application to function on a maximum number of computers.

You can check more on Microsoft Learn and for more such topics you can Search or Visit our C# Section too.

Leave a Reply

Your email address will not be published. Required fields are marked *