Retrieving the current directory in the assembly used by the web service application and the Windows service

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

This assembly is used by the Windows service and the web service.

The following is done in the Windows service:

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

However, from webservice baseDirectory is the directory to the bin directory in which the configuration file is located.

So, how do I get the assembly to find the file for both the Windows service and the web service?

Thanks JD.

+3
source share
1 answer

Why don't you just check if the configuration file exists in

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

, :

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

, " -".

+4

Source: https://habr.com/ru/post/1713837/


All Articles