Looping Through Application Settings

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a Windows Form application with several application settings set. How
is it possible for me to loop through those settings? Is it possible at all?

Thank you
 
<< Is it possible at all? >>

No - this is logically and technically impossible.
 
I have a Windows Form application with several application settings set. How
is it possible for me to loop through those settings? Is it possible at all?

Thank you

NameValueCollection settings;
settings = System.Configuration.ConfigurationManager.AppSettings;

foreach (string keyname in settings.AllKeys)
{
messagebox.show(keyname)
{
 
Hi,

As MWS suggested, the Settings is of type NameValueCollection and you can
use its AllKeys to iterate.

I'm not sure if this is what you wanted. Please feel free to let us know if
you have further questions. Thanks.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
MWS said:
NameValueCollection settings;
settings = System.Configuration.ConfigurationManager.AppSettings;

foreach (string keyname in settings.AllKeys)
{
messagebox.show(keyname)
{

This returns the error "The type or namespace name 'ConfigurationManager'
does not exist in the namespace 'System.Configuration'. I have to use
System.Configuration.ConfigurationSettings.AppSettings.

And that does not return any of my app settings.
 
Hello RHPT,
This returns the error "The type or namespace name
'ConfigurationManager' does not exist in the namespace
'System.Configuration'. I have to use
System.Configuration.ConfigurationSettings.AppSettings.

And that does not return any of my app settings.

You need to add a reference to the System.Configuration to your project.
These classes used to reside in the .NET Core Assembly, but were moved to
a separate assembly for .NET 2.0.

Jess
 
Hi,

Are you using the Client Settings (created with the Settings Designer)? In
other words, you have a strong typed settings class and you access the
settings via strong typed property name:

Settings.Default.MyProperty


If this is the case, then the AppSettings will not help here since it's
using different approaches.


To get the property name list, you can use Settings.Default.Properties to
iterate them:

foreach (SettingsProperty sp in Settings.Default.Properties)
{
Console.WriteLine(sp.Name);
}

After you get the property name, then you can use reflection on the
Settings.Default object to get the property value. You can also use
SettingsProperty.DefaultValue to get the default value when you input in
the settings designer.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
"Walter Wang [MSFT]" said:
Hi,

Are you using the Client Settings (created with the Settings Designer)? In
other words, you have a strong typed settings class and you access the
settings via strong typed property name:

Settings.Default.MyProperty


If this is the case, then the AppSettings will not help here since it's
using different approaches.


To get the property name list, you can use Settings.Default.Properties to
iterate them:

foreach (SettingsProperty sp in Settings.Default.Properties)
{
Console.WriteLine(sp.Name);
}

After you get the property name, then you can use reflection on the
Settings.Default object to get the property value. You can also use
SettingsProperty.DefaultValue to get the default value when you input in
the settings designer.


Thank you. This is what I was looking for. I should have asked my question
better.
 

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

Back
Top