我有简单的C#控制台应用程序,可以从同一目录中的config.ini
获取数据。参考config.ini
实施的Environment.CurrentDirectory
:
IniFile myIni = new IniFile(Environment.CurrentDirectory + "\\config.ini");
问题是,当我使用Scheduler
运行应用时,它无法找到config.ini
的路径。如何设置此类路径以使用Scheduler
运行应用程序?
答案 0 :(得分:0)
// 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);