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.
Step 2
Select console application project and set the saved file.
Add the below namespace for the Access method of getting the path.
- using System;
- using System.IO;
Now, write the below code for getting the application startup path.
- static void Main(string[] args)
- {
- var GetDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
-
- Console.WriteLine(GetDirectory);
-
- Console.ReadKey();
- }
The above code displays a path of the application on the screen. See the below output.