0

I have simple C# console app that gets data from config.ini located in same directory. Reference to config.ini implemented with Environment.CurrentDirectory:

IniFile myIni = new IniFile(Environment.CurrentDirectory + "\\config.ini");

Problem is when I'm running app with Scheduler, it can't find path to config.ini. How to set such path for running app with Scheduler?

shmnff
  • 647
  • 2
  • 15
  • 31

1 Answers1

1

Try this

// to get the location the assembly is executing from
//(not necessarily where the it normally resides on disk)
// in the case of the using shadow copies, for instance in NUnit tests, 
// this will be in a temp directory.
string path = System.Reflection.Assembly.GetExecutingAssembly().Location;

//To get the location the assembly normally resides on disk or the install directory
string path = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;

//once you have the path you get the directory with:
var directory = System.IO.Path.GetDirectoryName(path);
Héctor M.
  • 2,302
  • 4
  • 17
  • 35
  • There are better ways for a console app to do this than to include the Windows.Forms assembly... –  Mar 07 '18 at 00:19