Eran Kampf
Eran Kampf
1 min read

Configuration Application Block

Recently I’ve encountered a problem where I had to dynamically insert new configuration sections to Microsoft’s Configuration Application Block.

At first glance this seems impossible but digging further into the application block’s code I found it could be easily done using the following code:

ConfigurationSectionData newSection = new ConfigurationSectionData(
  new XmlFileStorageProviderData("Xml provider", "someFile.xml"),
  new XmlSerializerTransformerData()

ConfigurationSettings settings = ConfigurationManager.GetCurrentContext().GetMetaConfiguration();

ConfigurationManager.WriteConfiguration("NewSectionName", _settings);