ExeConfigurationFileMap cf =
new ExeConfigurationFileMap() { ExeConfigFilename = "C:\\app.config" };
Configuration configFile = ConfigurationManager.OpenMappedExeConfiguration(cf, ConfigurationUserLevel.None);
This by default provides KeyValuePair when you attempt to read the settings. To return KeyValuePair as NameValuePair, Use as below.
ExeConfigurationFileMap cf =
new ExeConfigurationFileMap() { ExeConfigFilename = "C:\\app.config" };
Configuration confFile = ConfigurationManager.OpenMappedExeConfiguration(cf, ConfigurationUserLevel.None);
NameValueCollection _collsettings = new NameValueCollection();
foreach (string key in confFile.AppSettings.Settings.AllKeys)
{
_collsettings.Add(confFile.AppSettings.Settings[key].Key, confFile.AppSettings.Settings[key].Value);
}
If you are reading machine config file, make use of Suitable class instead of Execonfigurationfilemap.
No comments:
Post a Comment