How to access default user settings ?

R

RedHair

I developed a Win form with VS.NET 2005 + .NET 2.0 in C#
There are some application settings are "User" scope and stored in
xxx.settings,
I can access them via Settings class and changethem with Settings.Save();
However, if I change and save them then my app will read the change from
the user.config , my question is how to access the original default setting?
 
K

Kevin Spencer

No, there is nothing ready-made to do this. If you use the Visual Studio
Project Settings to create the Application Settings, what it does is to
create both a Configuration file and a class that inherits
System.Configuration.ApplicationSettingsBase. The class is used in an
application to retrieve values in the Application Configuration file.
Settings are defined as being Application-scoped or User-scoped via
attributes, as well as the default values for User Settings, with the
System.Configuration.DefaultSettingValueAttribute. So, since the default
values are not exposed as properties in the class, you would have 2 possible
ways to get at them:

1. Use reflection on the class to get the values of the attributes.
2. Write your own custom Application Settings class.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

The shortest distance between 2 points is a curve.
 
R

RedHair

Thank you!
While creating the Settings.settings with VS.NET 2005, there is also a
app.config file?
I should add *.settins or *.config file to read/write application settings?
 

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