Get Current File Path

I have a program that reads a text file. It works perfectly, unless I have the “Task Scheduler” built into Windows 10 run it. If I run my .exe file manually, as long as my config.txt file is in the same folder as the .exe, it can find the file with no problem.

However, when using the Task Scheduler, it tries to look for the config file in a completely different folder. Specifically the system32 folder.

This is the line of code that makes this happen:

var lines = File.ReadAllLines(“config.txt”);

How do I force the File.ReadAllLines to look for the config.txt file in the same folder of the .exe that launches the code in the first place?

submitted by /u/Xebarsis
[link] [comments]

Leave a Reply