I have a service in C#, it uses a config.xml file for configuration.
I want to deplay the xml along side with the service executable. But I can’t seem to understand where to find the service exe installed location at runtime so that I could find/load the config.
Help please.
The static method
Assembly.GetEntryAssembly()will give you a reference to the entry assembly (the .exe file), and theLocationproperty will give you the location of the file:Another way around, if you know of a type in the entry assembly, is to use the
Type.Assemblyto get a reference to the assembly:If you need just the directory path, use the static
Path.GetDirectoryName()method.Off topic: have you considered the configuration API built into .NET? I am not saying this will be better in your specific case, but I guess it is worth considering before rolling your own configuration framework.