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(
"NewSectionName",
false,
new XmlFileStorageProviderData("Xml provider", "someFile.xml"),
new XmlSerializerTransformerData()
);
ConfigurationSettings settings = ConfigurationManager.GetCurrentContext().GetMetaConfiguration();
settings.ConfigurationSections.Add(newSection);
ConfigurationManager.WriteConfiguration("NewSectionName", _settings);