Cloud Training (Online)




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

Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.