I want to use the configuration of my application to store settings for 2 companies, and I would prefer if you could use the section to separate data for one from the other, and then give them different key names.
I check online, but I seem to be a little overwhelmed when people use partitions or find outdated simple ways to use them. can someone pass me a beginner's guide?
The following is an example of my app.config:
<configSections> <section name="FBI" type="" /> <section name="FSCS" type="" /> </configSections> <FSCS> <add key="processingDirectory" value="C:\testfiles\ProccesFolder"/> </FSCS> <FBI> <add key="processingDirectory" value="C:\testfiles\ProccesFolder"/> </FBI>
Update:
Anwer based advanced solution. in case someone wants to find out.
App.config:
<configuration> <configSections> <sectionGroup name="FileCheckerConfigGroup"> <section name="FBI" type="System.Configuration.NameValueSectionHandler" /> <section name="FSCS" type="System.Configuration.NameValueSectionHandler" /> </sectionGroup> </configSections> <FileCheckerConfigGroup> <FSCS> <add key="processingDirectory" value="C:\testfiles\ProccesFolder"/> </FSCS> <FBI> <add key="processingDirectory" value="C:\testfiles\ProccesFolder"/> </FBI> </FileCheckerConfigGroup> </configuration>
the code:
// Get the application configuration file. System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); // Get the collection of the section groups. ConfigurationSectionGroupCollection sectionGroups = config.SectionGroups; foreach (ConfigurationSectionGroup sectionGroup in sectionGroups) { if (sectionGroup.Name == "FileCheckerConfigGroup") { foreach (ConfigurationSection configurationSection in sectionGroup.Sections) { var section = ConfigurationManager.GetSection(configurationSection.SectionInformation.SectionName) as NameValueCollection; inputDirectory = section["inputDirectory"]; //"C:\\testfiles"; } } }
Andy Jan 12 2018-11-11T00: 00Z
source share