How to determine current EXE directory for a C# console application

1

I tried to determine current running directory of my C# console application using the following code:

Assembly.GetExecutingAssembly().Location

However that code returns path to assembly location. It may be different from the folder where EXE file is located.

My console application parses logs with no parameters. I want to know the path to the logs/ folder inside of the current executable's folder. Please help!

Tags: , ,

3 answers

In the ASP.NET. Have you ever wanted to get the directory for the executing Console Application in C#? The following method will do so, and is the equivalent of Application.StartupPath when working with Windows Forms.

System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)
User rating:

Thanks, here is my tip!

User rating:

Here is another tip

0

You can use following method:

System.Reflection.Assembly.GetExecutingAssembly().Location
User rating:

Thank you

0

Hi

you can use "Directory.GetCurrentDirectory" to get the current working directory of the application.

0

Post Answer