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

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

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...