Geeks With Blogs
Randy Walker Entrepreneur, VB MVP

I had come across an article where you can use the following line to read custom section settings from your config file (where SectionName is the name of your section) in .Net.

NameValueCollection myData = (NameValueCollection)System.Configuration.ConfigurationManager.GetSection(SectionName);

The advantage of this is your setting doesn't have to be in the app.config file (web.config).  You can have a file named mywackyweirdfilename.config, and you use the exact same line.  The beauty of it is in the app.config (web.config) file where you point it to reference the mywackyweirdfilename.config.  e.g.

     <section name="SectionName" type="System.Configuration.NameValueFileSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SectionName file="mywackyweirdfilename.config" />

Why is this such a beautiful way to handle your config file?  Because if you distribute your application, the system administrator can decide where to put the mywackyweirdfilename.config file.  It could, in fact, reside on a public share (although not recommended in case of the network being unavailable) or thumb drive.

So what's the problem?  You can't write to the config file easily.  I'll do a later post on my solution for writing to the config file, in which the format of the mywackyweirdfilename.config does not match below .

The format of mywackyweirdfilename.config for the examples above:

<?xml version="1.0" encoding="utf-8" ?>
     <add key="myKey" value ="" />

Technorati Tags: ,,
Posted on Wednesday, March 26, 2008 9:34 PM | Back to top

Comments on this post: Preferred method for read only Config files

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Randy Walker | Powered by: