Simple application configuration reader/writer class

app.config and web.config are very powerfull techniques for managing application settings. For more information about using configuration file please check this article in MSDN

But the manipulation of these files has 2 issues

1) There’s no class in .NET framework to update the files so you have to write your own code to access the configuration file as any xml file and update it

2) Even If you did so, the ConfigurationSettings.AppSettings property caches the values of the when it reads them for the first time so if you read a value from app.config then you changed it and re-read it again, you will get the old value.

For those two reasons, I developed a very simple assembly called simpleConfiguration which has 1 class called AppSettings and this AppSettings class has an indexer to get/set the values of the configuration settings. And this library is thread-safe.

To read from your app.config file just use these two lines

C#

simpleConfiguration.AppSettings settings=new simpleConfiguration.AppSettings();

string myValue=settings[“myValuekey”];

VB

Dim settings As New simpleConfiguration.AppSettings

Dim name As String = settings.Item("myValuekey ")

To write to app.config

C#

simpleConfiguration.AppSettings settings=new simpleConfiguration.AppSettings();

settings[“myValuekey”]=”myValue”;

VB

Dim settings As New simpleConfiguration.AppSettings

Settings.Item(“myValuekey”)=”myValue

To download the assembly go here and to download the source files here

cheers,
Mohamed