How to read Default Values from App.Config for User Settings?

  • Thread starter Thread starter herceg
  • Start date Start date
H

herceg

Hi all;

How can I read default values for user settings from the app.config
file? I've seen someone mention using
the .DefaultSettingValueAttribute and reflection, but I don't know how
to use them.

I am trying to do the following:

1) Create a simple Windows App that has one user setting named
"SupportAddress" and a default (string) value.

2) The default support address is in the App.Config file.

3) Make a form which allows users to modify and save the setting. This
creates the User.Config file in the Application Data folder.

4) This I don't know - If the users mess up the support address value,
I want to allow them to read the default value for the SupportAddress
setting from the App.Config, not from the User.Config file. Of course,
there will be a button named "Revert to Default" or similar on the
form. What should I do?

Thanks in advance,

Djordje
 
sample contents of the Config file.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="SupportAddress" value="theDefaultValue"/>
</appSettings>
</configuration>



//code to read the SupportAddress
AppSettingsReader settingsReader = new AppSettingsReader();
string default = settingsReader.GetValue("SupportAddress",
typeof(string)).ToString();

===================
Clay Burch
Syncfusion, Inc.
 
Back
Top