Automated application configuration with XML and .NET 2.0
Have you tried classes from System.Configuration namespace in you Visual Studio 2005 project? Well you should. If you haven't simply start a new Windows Application Project and see what is hidden in "Properties" branch in you solution tree window. Double click on Settings entry and using UI tool for binding configuration entries you'll notice how easy is to add a new application/user scope configuration keys for your new application.
How to use them in your project from code side?
Well, simply see how Settings.Designer.cs class looks like to comprehend some basics.
You did? Perfect. Now in sample form you just got add some controls to show your configuration entries. For example TextBox for a string entry and how to fill it with real data you might ask.
Simply! Following code fragment should help you how to figure it out:
[
textboxSample.Text = Properties.Settings.Default.YourKeyEntry;
]
If you want to save a modified (in runtime) value of that configuration key simply reverse the order and add a line of code like below:
[
Properties.Settings.Default.YourKeyEntry = textboxSample.Text;
Properties.Settings.Default.Save();
]
It will save all the "User" scope entries to the XML file. "Application" scope entries are read only as static values in definitions (see MSDN for more details).
As you see building application wide configurations is very easy with .NET and Visual Studio .NET right?






