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

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();
        }
    }
}

Leave a Reply

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...