How to get the Application Directory in C#?

If you have been developing application using C#, I am sure you would have come across a situation where you have to find the Application Directory Path.

There are many ways to get the Application Directory in your C# Application. I have listed below some of the ways you can accomplish this.  


Method 1:

Here is an example of how you can get the Application Directory Name where you have your EXE.

This takes the Path of the EXE of your application and passes it to the GetDirectoryName method to get the name of the directory.


using System.IO;

using System.Windows.Forms;


string appPath = Path.GetDirectoryName(Application.ExecutablePath);


Method 2:

Next to get the Directory name of the Executing Assembly you can use the following code:


Here is an example of getting the Directory Name of the Executing Assembly.

         String strAppDir = Path.GetDirectoryName(


        String strFullPathToMyFile = Path.Combine(strAppDir, "fileName.txt");


        MessageBox.Show(String.Format("Path to the application is: '{0}'." +

            "Full path to the file in the application folder is: '{1}'",

            strAppDir, strFullPathToMyFile));


Method 3

You can use this code in your C# Windows Application to get the Application Directory Name

string msg = Application.StartupPath;


Method 4



Method 5



Method 6



Hope this was helpful.