PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

configuration setting

 
 
Andrew
Guest
Posts: n/a
 
      18th Mar 2008
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
 
Reply With Quote
 
 
 
 
Andrew
Guest
Posts: n/a
 
      19th Mar 2008
I found this information that solves my problem.

http://forums.microsoft.com/MSDN/Sho...04936&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

"Andrew" wrote:

> 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

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
alternate configuration setting is not used Andrew Windows XP Networking 0 21st Jan 2009 05:01 PM
In my xp O.S Lan setting in ' Use automatic configuration Script ' =?Utf-8?B?YXl5dWI=?= Windows XP Help 0 22nd Jun 2006 09:59 AM
configuration setting in hirarchy =?Utf-8?B?UGlldGVyTQ==?= Microsoft ASP .NET 0 19th Dec 2005 12:11 PM
Setting up POP Configuration - pwd not recognized jillaine.smith@gmail.com Microsoft Outlook Installation 0 13th Jul 2005 02:42 PM
configuration setting =?Utf-8?B?bXd3Nw==?= Windows XP Performance 2 4th May 2005 05:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:39 AM.