I have a utility application which allows user to import/export data from various databases. Each new task is added by adding a custom config section in app.config as shown below. Over the time the app.config file has grown very large & to keep things simple, I wanted user to be able to add new task in separate file. I have read options where appSettings
or connectionString
settings can be moved to different config file by specifying configSource
attribute. Is it possible to do the same for custom sections?
Example of custom section which I use internally for task configuration.
<configSections>
<sectionGroup name="tasks">
<sectionGroup name="ImportData">
<section name="transferType" type="System.Configuration.NameValueSectionHandler"/>
<section name="srcConnectionString" type="System.Configuration.NameValueSectionHandler"/>
<section name="srcProcedure" type="System.Configuration.NameValueSectionHandler"/>
<section name="destConnectionString" type="System.Configuration.NameValueSectionHandler"/>
<section name="destTable" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</sectionGroup>
</configSections>
<tasks>
<ImportData>
<transferType>
<add key="transferType" value="database" />
</transferType>
<srcConnectionString>
<add key="srcConnectionString" value="sourceDB" />
</srcConnectionString>
<srcProcedure>
<add key="srcProcedure" value="sourceProcedureName" />
</srcProcedure>
<destConnectionString>
<add key="destConnectionString" value="destConnection" />
</destConnectionString>
<destTable>
<add key="destTable" value="TableName" />
</destTable>
</ImportData>
</tasks>
The section value is read like
NameValueCollection transferSection = (NameValueCollection)ConfigurationManager.GetSection("ImportData/transferType");
How to add new sections in separate file & still continue to be able read the same way.