Coding adventures with Happy results

Get The Current Directory in .Net Core

Monday, September 7, 2020 | 12:01:05 AM | C#

Back in the old days of .Net full, we use the AppDomain.CurrentDomain.BaseDirectory.

Let's see what we can use for the creation of a .Net Core Application.

 

The following method will return the working directory using the System namespace.  If you are running your project bin\debug in debug mode, this method will Output your project bin\debug folder following by "\".

Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory);

AppDomain represents an application domain, which is an isolated environment where applications execute.

 

The following method will return the working directory using the System.IO namespace.  If you are running your project bin\debug in debug mode, this method will Output your project bin\debug folder.

Console.WriteLine(Directory.GetCurrentDirectory());

 

Consider that in .NET Core this is the current best practice.

 

Until next time,

Happy Coding!