How to get the application folder path in C#? Best ways
Hello everyone! I'm a beginner C# developer and I have a problem. I need to save some configuration files and temporary data next to my application. I tried using `Application.StartupPath` in WinForms, but when I switched to a console application, this property turned out to be unavailable. Then I tried `Directory.GetCurrentDirectory()`, but it returns not the folder where the .exe is located, but the folder from which I run the program (for example, when running from Visual Studio, this is the bin/Debug folder).
Here is an example of my code that doesn't work as expected:
```csharp
string configPath = Path.Combine(Directory.GetCurrentDirectory(), "config.xml");
// The file is created not next to the exe, but in the startup folder
```
I've heard about `Assembly.GetExecutingAssembly().Location` and `AppDomain.CurrentD
No answers yet.
Log in to leave an answer
Blogs