configuration setting

A

Andrew

Hi,

I want to display the list of setting names in my app.config file in a
combobox.

In my app.config file :
<applicationSettings>
<My.Properties.Settings>
<setting name="sSetting1" serializeAs="String">
<value>sSetting1</value>
</setting>
<setting name="sSetting2" serializeAs="String">
<value>sSetting2</value>
</setting>
<My.Properties.Settings>
<applicationSettings>
.....
Code :
Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// Get sectiongroup
ConfigurationSectionGroup sectionGroup =
config.GetSectionGroup(sectionGroupName);
// Get section
ClientSettingsSection section =
(ClientSettingsSection)sectionGroup.Sections.Get(sectionName);
// Get settings
SettingElementCollection setting = section.Settings;
// Display setting
arlistRSN = new ArrayList();
for (int i = 0; i < setting.Count; i++)
arlistRSN.Add("XXXX");
myArr = (string[])arlistRSN.ToArray(typeof(string));
return myArr;

I could get the Count=2. How do I get the values XXXX to put into my
arraylist ?
Is it possible to get the list of settings from the
"SettingElementCollection" class ?
The values that I pick up should be "sSetting1" and "sSetting2".

cheers,
Andrew
 
A

Andrew

I found this information that solves my problem.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=504936&SiteID=1

//ClientSettingsSection -> SettingElementCollection -> ConfigurationElement
-> SettingElement

SettingElementCollection sec = section.Settings;
//ConfigurationElement is an array
ConfigurationElement[] el = new ConfigurationElement[section.Settings.Count];
//Copy ConfigurationElements into the array
sec.CopyTo(el, 0); //start at zero
SettingElement se = (SettingElement)el.GetValue(0); //get the first element
string elem1 = se.Name; //from that element, get the name
string elem2 = se.Value.ValueXml.FirstChild.InnerText; //get the value

cheers
Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top