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);

HOW TO GET THE CURRENT EXECUTABLE'S PATH IN C#

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 *

Explore More

Working With File Class In C#

In C#, ‘File’ class provides many static methods for moving, copying, and deleting files. These Static methods involve moving a file and copying and deleting a file also. Let’s check

How to Read a Text File in C#

In C# ‘File’ class provides static methods to read given text file data. The File.ReadAllText() method opens a text file, reads all the text present in the file into a

C# | How to use Interface references

In C#, you’re permitted to make a reference variable of an interface type or in other words, you’re permitted to form an interface reference variable. Such kind of variable can