C# Tips and Tricks #6 – Find the Application Path in Console Application

There are times when you are working on a console application in C# and you might want to get the application path. You might notice that the Application.StartupPath would not be available in console application which exists in the Winforms.

How to get Application Path in a Console Application in C#?

You can use the reflection to get it easily using the property

System.Reflection.Assembly.GetExecutingAssembly().Location

Here’s a sample code demonstrating how to get the application path in console application in C#.

using System;
namespace ConsoleApp1
{
    class Program
    {   
        static void Main(string[] args)
        {

            string path = System.Reflection.Assembly.GetExecutingAssembly().Location;
            Console.WriteLine(path);
            Console.ReadLine();
        }
    }
}

Pin It

Leave a Reply

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