Click here to Skip to main content
Licence 
First Posted 29 Apr 2003
Views 68,539
Bookmarked 35 times

SettingsXpress - Application Settings Made Easy

By | 10 May 2003 | Article
Application Settings Storage and Retrieval Simplified

Introduction

With SettingsXpress you can easily create an XML settings file for your application, to store and retrieve application settings, using a streamlined code interface.

SettingsXpress can store and retrieve all native CLS compliant DotNet data types as well as Point, Size, Color, Guid, DateTime and TimeSpan settings without the need to parse string values.

The SettingsFile class acts as a virtual storage facility for your application and component settings. The settings file is organized in a hierarchical format, based on a logical ordering of SettingsKeys stored within it.

By default the settings file is stored in the current users AppData folder for the current client application. You can also specify a custom location and filename for the settings file using the SettingsFile.Create method.

A SettingsKey is the base unit of organization in the settings file, and can be compared to a folder. A particular key can have subkeys (just as a folder can have subfolders)

Each SettingsKey can have multiple settings stored within it. Each setting holds one particular value, which can be retrieved or updated when required.

Using SettingsXpress

Creating SettingsKeys and storing settings

To use your application settings file, you start by accessing the static Settings property of the SettingsFile class, which returns the root SettingsKey in the settings file.

To create a subkey use the CreateSubKey method. Once a SettingsKey is established you can now store settings using the StoreSetting method.

SettingsKey dataSettings = SettingsFile.Settings.
            CreateSubKey("DataManager/Connection");
dataSettings.StoreSetting("DriverType", 
            "Microsoft Excel");

Note: When you first access the settings file in your code, it is automatically loaded or created. To specify a specific location for the settings file use the SettingsFile.Create method.

The above code generates the XML settings file as follows :

<Settings>
    <DataManager>
      <Connection DriverType = "Microsoft Excel"/>
    </DataManager>
</Settings> 

Once you have settings established in the settings file, use the SettingsFile.Update method to update the settings file.

Retrieving SettingsKeys and settings

To retrieve a SettingsKey in the settings file you have the following options:

  • Use the SettingsKey.OpenSubkey method.
  • Use the SettingsKey[path] indexer.
  • Use the SettingsKey.CreateSubKey method

Tip : The SettingsKey.CreateSubkey method is a good option to use, when you are not certain if the key is yet to establish in the settings file.

To retrieve a setting stored within a SettingsKey, use the SettingsKey's GetSetting, GetPoint, GetSize, or GetColor methods.

The following code retrieves the width of a TreeView from the settings file.

SettingsKey TreeViewSettings = SettingsFile.
                Settings["UI/MainWindow/TreeView"];
int width = TreeViewSettings.GetSetting
            ("Width",this.TreeView.Width);

History

  • 04/20/2003 - Test release v0.5
  • 05/11/2003 - Release v1.1 with source

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Amber Star



United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralGetColor Problem Pinmemberqstar2k7:50 28 Apr '08  
GeneralSadly, contact email in source is also dead PinmemberPerry214:22 8 Mar '06  
QuestionRe: Sadly, contact email in source is also dead PinmemberAmber Star23:34 8 Mar '06  
AnswerRe: Sadly, contact email in source is also dead PinmemberPerry26:21 9 Mar '06  
AnswerRe: Sadly, contact email in source is also dead PinmemberAmber Star11:03 9 Mar '06  
GeneralRe: Sadly, contact email in source is also dead PinmemberPerry27:53 10 Mar '06  
GeneralWrong contact info url PinmemberPerry27:45 8 Mar '06  
QuestionSource formatting is not MS-Windows? PinmemberPerry28:05 7 Mar '06  
GeneralDeleting a section PinmemberMark Lerch11:32 28 May '04  
GeneralRe: Deleting a section PinmemberMark Lerch12:14 28 May '04  
GeneralRe: Deleting a section PinmemberAmber Star12:41 28 May '04  
GeneralRe: Deleting a section PinmemberMark Lerch12:46 28 May '04  
GeneralGreat Solution Pinmemberpestrada3:16 11 Mar '04  
QuestionDoc? PinmemberSteven Carleton14:21 18 Jul '03  
QuestionSpaces in key names? Pinmemberbaldo22:19 1 Jul '03  
AnswerRe: Spaces in key names? PinmemberAmber Star10:31 2 Jul '03  
QuestionCan we have more usage examples please? PinmemberTintinAndSnowy19:43 13 May '03  
AnswerRe: Can we have more usage examples please? PinmemberAmber Star14:00 14 May '03  
Generalnunit.framework missing reference Pinmemberbaldo22:59 11 May '03  
GeneralRe: nunit.framework missing reference PinsussAnonymous7:04 12 May '03  
GeneralSource code is Included PinmemberAmber Star11:44 11 May '03  
QuestionTotally awesome -- where's the source? Pinmembercwkingjr2:25 9 May '03  
AnswerRe: Totally awesome -- where's the source? PinmemberDarka2:35 9 May '03  
GeneralRe: Totally awesome -- where's the source? Pinmemberpeterchen3:37 12 May '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 11 May 2003
Article Copyright 2003 by Amber Star
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid