Home All Groups Group Topic Archive Search About

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

Author
16 Apr 2007 12:54 PM
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
Author
16 Apr 2007 1:29 PM
ClayB
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.

Bookmark and Share