The standard approach for separating settings for individual files is to use the ConfigSource ConfigurationSection . Therefore, if you want to save ALL of your AppSettings in "ait.config", you can do like this:
<appSettings configSource="ait.config" />
Please note that this only works if you save ALL of your AppSettings in a separate file. If you try to save some parameters in your main application configuration file, for example:
<appSettings configSource="ait.config"> <add key="Culture" value=""/> <add key="ClientSettingsProvider.ServiceUri" value=""/> </appSettings>
You get an exception saying something like " Sections should only appear once in the configuration file. ".
You should probably use the Customizing section for general configurations, try:
Here is a simple example to get you started:
Define your section:
public class CommonConfSection : ConfigurationSection { private const String UserNameProperty = "Username"; [ConfigurationProperty(UserNameProperty, DefaultValue = "__UNKNOWN_NAME__", IsRequired = false)] public String UserName { get { return (String)this[UserNameProperty]; } set { this[UserNameProperty] = value; } } }
App.config:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="CommonSettings" type="[Your Assembly Name].CommonConfSection, [Your Assembly Name]" /> </configSections> <appSettings> <add key="Culture" value=""/> <add key="ClientSettingsProvider.ServiceUri" value=""/> </appSettings> <CommonSettings configSource="common.config" /> </configuration>
Note:
- configSections MUST be the first child of a configuration node ;
- The CommonSettings : configSource = "common.config" section says that the settings for this section are stored in a file called " common.config >" (in the same folder).
And here is what common.config looks like :
<?xml version="1.0" encoding="utf-8" ?> <CommonSettings Username="testUser" />
source share