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

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...