First, you need to write a custom class for each custom section in the configuration file; another option is to use one of the built-in types.
For example;
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="Default" type="System.Configuration.NameValueSectionHandler" />
<section name="Maestro" type="System.Configuration.NameValueSectionHandler" />
<section name="Drive" type="System.Configuration.NameValueSectionHandler" />
</configSections>
<Default>
<add key="gmasIP" value="192.168.2.3" />
<add key="hostIP" value="192.168.2.2" />
<add key="GatewayIP" value="192.168.2.4" />
<add key="relayCOM" value="6" />
</Default>
<Maestro>
<add key="Wireshark" value="1" />
</Maestro>
<Drive>
<add key="FirmwarePath" value="C:\Users\rinat\Desktop\Download.txt/>
<add key="FirmwarePalPath" value="C:\Users\rinat\Desktop\Download.txt" />
</Drive>
</configuration>
If you want to get the values as an array:
var defaultItems= ConfigurationManager.GetSection("Default") as NameValueCollection;
List<string> temp = new List<string>();
if (defaultItems!= null)
{
foreach (var key in defaultItems.AllKeys)
{
string val= defaultItems.GetValues(key).FirstOrDefault();
temp.Add(val);
}
}
string[] arr = temp.ToArray();