C# Windows Service Multiple Config Files
Posted
by Goober
on Stack Overflow
See other posts from Stack Overflow
or by Goober
Published on 2010-04-14T17:22:00Z
Indexed on
2010/04/14
17:33 UTC
Read the original article
Hit count: 211
Quick Question
Is it possible to have more than 1 config file in a windows service? Or is there some way I can merge them at run time?
Scenario
Currently I have two config files containing the below contents. After I build and install my Windows Service, I can't get my custom XML Parser class to read the content because it keeps pointing to the wrong config file, even though I am using a few lines of code to ensure it gets the right name of the config file I need to access.
ALSO
When I navigate to the folder in which the service is installed, there is only sign of the normal APP.Config file, and no sign of the custom config file. (I have even set the normal ones properties to "Do Not Copy" and the custom ones properties to "Copy Always").
Config File Determination Code
string settingsFile = String.Format("{0}.exe.config",
System.AppDomain.CurrentDomain.BaseDirectory
+ Assembly.GetExecutingAssembly().GetName().Name);
CUSTOM CONFIG File
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<servers>
<SV066930>
<add name="Name" value = "SV066930" />
<processes>
<SimonTest1>
<add name="ProcessName" value="notepad.exe" />
<add name="CommandLine" value="C:\\WINDOWS\\system32\\notepad.exe C:\\WINDOWS\\Profiles\\TA2TOF1\\Desktop\\SimonTest1.txt" />
</SimonTest1>
</processes>
</SV066930>
</servers>
</configuration>
NORMAL APP.CONFIG File
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxx" />
</configSections>
<connectionStrings>
<add name="DB" connectionString="Data Source=etc......" />
</connectionStrings>
</configuration>
© Stack Overflow or respective owner