Click here to Skip to main content
15,916,378 members
Articles / Programming Languages / C#
Article

Custom application configuration. [With Editor Demo]

Rate me:
Please Sign up or sign in to vote.
4.44/5 (6 votes)
15 Aug 2002 54.5K   1.4K   31   2
This class helps you to create and modify custom configuration files for your application.

Introduction

In the line of software development many times I have come across situations where I needed some kind of functionality to read, write and modify basic configuration options for my application. Here is a basic solution.

The ConfigManager helps developers to the same task in a very easy manner.

ConfigManager class has the following members:

  • ConfigManager() - Constructor, creates application.config file as the default configuration file
  • ConfigManager(string) - Constructor, creates a configuration file by given parameter which is filename.
  • bool AddValue(string key,object value) - Adds a value by key. The key is unique.
  • bool RemoveValue(string key,object value) - Removes a value by key.
  • object GetValue(string key,object default) - Returns a value by key or the default. Creates the entry if it doesn't exists.
  • ArrayList GetValues(string key,object default) - Returns an ArrayList of values.
  • bool UpdateValue(string key,object default) - Updates a value by key.

How to use the ConfigManager

Here is a simple example of how to use the ConfigManager's GetValues()

C#
ConfigManager c = new ConfigManager();
ArrayList List = c.GetValues();

foreach(ConfigManagerKeyValue Item in List) {
    Console.WriteLine("{0,10} is {1,10}",Item.Key , Item.Value);
}

Have fun C#ing :)

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


Written By
Web Developer
Netherlands Netherlands
Gevik Babakhani is a software architect currently residing in The Netherlands. He started programming as hobby from the age of 12. His professional career began in 1997. Since then he works fulltime as a software architect. Currently he dedicates time and effort in Microsoft.NET.
This is a Organisation (No members)


Comments and Discussions

 
GeneralRun time changes Pin
pankajdc7-Oct-05 8:49
pankajdc7-Oct-05 8:49 
GeneralGood work. Pin
Sean Rock10-Jan-03 4:12
Sean Rock10-Jan-03 4:12 

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

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