How To Get Application Startup Path From The Console Application Using C#

In this post, we will learn how to get an application startup path from a console application using C#. Here is an example of how to get the path. For this, we are using some namespace and assembly for getting the path that is already added in this post. This example gets the path of the application and display on the screen and waits for the user to press a key.

Let's start coding.

Step 1

Create a new console application project by going to File -> New -> Project.

How To Get Application Startup Path From The Console Application Using C#

Step 2

Select console application project and set the saved file.

How To Get Application Startup Path From The Console Application Using C#

Add the below namespace for the Access method of getting the path.
  1. using System;  
  2. using System.IO; 
 Now, write the below code for getting the application startup path.
  1. static void Main(string[] args)  
  2. {  
  3.     var GetDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);  
  4.   
  5.     Console.WriteLine(GetDirectory);  
  6.   
  7.     Console.ReadKey();  

The above code displays a path of the application on the screen. See the below output.

How To Get Application Startup Path From The Console Application Using C#