C# – Getting the current directory in an assembly used by a web service app and windows service

c

I have an assembly that reads a configuration file which is in the application directory.

This assembly is used from a windows service and a web service.

From the windows service the following works:

string ConfigFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MyFile.config");

However from the webservice, baseDirectory is the directory before the bin directory where the config file is.

So how do I make the assembly find the file for both a windows service and a web service?

Thanks
JD.

Best Answer

Why do you not just check if the config file exists in

Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MyFile.config");

and if it does not you check here:

Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin\MyFile.config");

Hopefully I understood the description of the behaviour in the "webservice case" correctly.