How to get the Current Application Directory in C# ?

There are times when you might want to get the current application directory with the complete path. You can use the CurrentDirectory property defined in the System.Environment class to achieve this.

How to get the Current Application Directory in C# ?

The System.Environment.CurrentDirectory gets or sets a string that contains the current application directory.

Below is sample code snippet demonstrating how to get the current application directory from a console application in C#.

using System;

namespace DeveloperPublishApp
{
    class Program
    {
        static void Main(string[] args)
        {
            // Gets the current application directory
            var currentDirectory = Environment.CurrentDirectory;
            Console.WriteLine("The Current Application Directory is : " + currentDirectory);
            Console.ReadLine();
        }
    }
}

This would return the string as shown below.

The Current Application Directory is : c:\users\senthil\documents\visual studio 2015\Projects\DeveloperPublishApp\DeveloperPublishApp\bin\Debug

Leave a Reply