Class wwAppConfiguration

This class provides a Configuration Settings persistance manager. You can use it to store application configuration settings easily simply by creating a subclass with persistance to a configuration file taken care of automatically. It provides the following features:

  • Type Safe access to configuration settings - simply add properties to a class
  • Default values applied to config file. Never worry about null values
  • Support for writing to sections and separate config files
  • Support for writing to a Sql Server Table
  • Optional encryption of selected keys
  • Ability to write keys back into config file

You implement a configuration object by creating a new subclass of the wwAppConfiguration class and adding public Fields or Properties to the class. Every new member you add will be persisted to the application's .Config file. On first use the class also writes out default values into the .Config file so the data is always there. The data is always returned in a fully typed manner - you simply reference the properties of this object.

Values are stored in the AppSettings section of the .Config file by default and uses ApplicationSettings to internally retrieve this data. You can use SetConfigurationSection() to specify a different section in the file. The data is always returned in the proper type format rather than as string and null instances are never a problem as there will always be a default value returned. This reduces the amount of code that goes along with pulling data out of the .Config file.

Supported fields type are any simple types (string, decimal, double, int, boolean, datetime etc. ) as well as enums. Enums are persisted into the front end interface using strings (ie. if you use it in a listbox value the value must be string).

The class also provides the ability to encrypt keys by calling the SetEncryption() method with a list of keys and a password.

Namespace: Westwind.Tools
Inherits: Object

Class Members



Retrieves all values from an AppSettings style Configuration section as an untyped NameValueCollection.

public NameValueCollection GetAllKeysFromConfigSection(String Section)

public NameValueCollection GetAllKeysFromConfigSection(String Section, String Filename)


Returns a key from the Configuration Settings Section.

public String GetKeyFromConfigSection(String Key, String Section)

public String GetKeyFromConfigSection(String Key, String Section, String Filename)


Reads all the configuration settings from the .Config file into the public
fields of this object.

public Void ReadKeysFromConfig()

public Void ReadKeysFromConfig(String Filename)

public static wwAppConfiguration ReadKeysFromConfig(Type ConfigType)

public static wwAppConfiguration ReadKeysFromConfig(String Filename,Type ConfigType)


Reads the configuration settings from an XML file created with WriteKeysToFile.

public static wwAppConfiguration ReadKeysFromFile(String FileName, Type ConfigurationObjectType)


Reads keys from a SQL Database from a table you specify. Table must contain ID (int) and ConfigData fields.

public static wwAppConfiguration ReadkeysFromSqlServer(String ConnectionString, String TableName, Int32 Key, Type ConfigurationObjectType)


Reads the configuration settings from an XML string created with WriteKeysToString

public static wwAppConfiguration ReadKeysFromString(String Xml, Type ConfigurationObjectType)


Sets the Configuration File Section if the default is section is not used

public Void SetConfigurationSection(String ConfigurationFileSection)


Allows you to specify a set of fields to encrypt with a password key. Causes the specified keys to be encrypted whenever written to the output file.

public Void SetEnryption(String EncryptFields, String EncryptKey)


Writes all of the configuration file properties to the configuration file.

public Boolean WriteKeysToConfig()

public Boolean WriteKeysToConfig(String Filename)


Serializes the the current object into a file in XML format on disk

public Boolean WriteKeysToFile(String FileName)


Writes the Configuration Settings into a SQL Server of your choice table and a field called ConfigData.

public Boolean WriteKeysToSqlServer(String ConnectionString, String TableName, Int32 Key)


Writes the Configuration Settings to an XML String. You can then do what you need to with the string to store where you please.

public Boolean WriteKeysToString(out String XmlResultString)

See also:

Class WebStoreConfig

© West Wind Technologies, 1996-2018 • Updated: 11/30/04
Comment or report problem with topic