Sitemap
.Net Programming

Explore the .Net with the latest in C# from basic to advanced, including .Net versions 9, 8, 6, 5, Core 3.1, .Net Framework, ASP.NET Core, MVC, design patterns, OOPS, and SOLID principles. Get top tutorials, best practices, and hands-on code examples on GitHub.

Member-only story

Exploring Different Methods to Fetch the Application’s Path

2 min readFeb 29, 2024

--

Photo by Mitchell Luo on Unsplash

The article showcases various methods to retrieve the application’s path in a .NET console application.

1. Utilizing AppDomain.CurrentDomain.BaseDirectory

A straightforward and widely used method is to employ the AppDomain.CurrentDomain.BaseDirectory property. This property returns the base directory where the application is currently running.

string appPath = AppDomain.CurrentDomain.BaseDirectory;

2. Employing Assembly.GetExecutingAssembly().Location

Another approach is to use the Assembly.GetExecutingAssembly().Location property. This provides the file path of the assembly (executable) containing the currently executing code.

string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

--

--

.Net Programming
.Net Programming

Published in .Net Programming

Explore the .Net with the latest in C# from basic to advanced, including .Net versions 9, 8, 6, 5, Core 3.1, .Net Framework, ASP.NET Core, MVC, design patterns, OOPS, and SOLID principles. Get top tutorials, best practices, and hands-on code examples on GitHub.

Sukhpinder Singh | C# .Net
Sukhpinder Singh | C# .Net

Written by Sukhpinder Singh | C# .Net

C# .Net developer 👨‍💻 who's 100% convinced my bugs are funnier than yours. 🐛💥 #BugLife Pubs: https://medium.com/c-sharp-programming