PC Review


Reply
Thread Tools Rate Thread

Config Files and Custom Sections

 
 
Doug Ransom
Guest
Posts: n/a
 
      15th Aug 2003
How can one add a section to their configuration file which allows for
whatever XML the author wants? The
System.Configuration.SingleTagSectionHandler doesn't work if I want my own
xml elements within the config file.

The config file mechanism seems really bizaree to me. I cannot understand
the advantage provided with the current format over just having an XML file
and allowing people to put in their own elements and read out what they
expect to be there, and the dotnet framework Configuration.Settings could
have just provided the file location or XML DOM Tree. If I wanted
everything to be key/value pairs, an ini file would have been good enough.



 
Reply With Quote
 
 
 
 
Richard Grimes [MVP]
Guest
Posts: n/a
 
      3rd Sep 2003
Doug Ransom wrote:
> How can one add a section to their configuration file which allows for
> whatever XML the author wants? The
> System.Configuration.SingleTagSectionHandler doesn't work if I want
> my own xml elements within the config file.
>
> The config file mechanism seems really bizaree to me. I cannot
> understand the advantage provided with the current format over just
> having an XML file and allowing people to put in their own elements
> and read out what they expect to be there, and the dotnet framework
> Configuration.Settings could have just provided the file location or
> XML DOM Tree. If I wanted everything to be key/value pairs, an ini
> file would have been good enough.


Its actually quite straightforward.

1) add a <section> or a <sectionGroup> and <section> for your new XML
section in the configuration file. This can be your app config file or
machine.config
2) in <section name> give the name of your section
3) in <section type> give the full type name of a handler (ie the full name
including the namespace and the full name of the assembly)
4) create an assembly that has the handler that implements
IConfigurationSectionHandler. This class should have a method called
Create() that is called when code tries to access your section. Your code
should read the section and create an appropriate object from the data, for
example a HashTable.
5) your client code calls ConfigurationSettings.GetConfig to read the
section. If the section is nested then you give the full path within the
<configuration> node with XPath like syntax (ie separate the elements of the
path with /).

Here is a simple example that illustrates what I have said:

http://www.grimes.demon.co.uk/Downlo...stomConfig.zip

The code creates a new section that describes a form. The section handler
reads this information, creates the form and controls on the form and
returns the form so that it can be displayed.

Richard
--
my email (E-Mail Removed) is encrypted with ROT13 (www.rot13.org)


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom config sections scott ocamb Microsoft Dot NET Framework 0 27th Aug 2008 07:43 PM
Conflicing My.MySettings sections in web.config files cmay Microsoft ASP .NET 2 7th Aug 2007 11:04 PM
Parsing sections from individual Web.config files. DarthContinent@gmail.com Microsoft ASP .NET 3 8th Nov 2006 08:29 PM
RE: C# 2.0: How to have app.config or web.config sections in separated =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?= Microsoft C# .NET 1 23rd Jan 2006 06:07 AM
Re: C# 2.0: How to have app.config or web.config sections in separated files? Nicholas Paldino [.NET/C# MVP] Microsoft C# .NET 0 22nd Jan 2006 03:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:33 AM.