Using a config file

  • Thread starter Thread starter Emjay
  • Start date Start date
E

Emjay

Hello, there.

I'm working on a .NET component library and I need to
have a config file to be used by the library components.
But as a newcomer to the .NET technology, I don't know
where and how to start.

The idea is that, as you may have already noticed,

- the config file(s) has information that is used by the
components of the library.
- the components of the library should be able to load
the files, assuming that it is stored in a particular
place(eg. a 'config' folder), wherever the library is
deployed.
- application developers should be able to modify the
information in the config file and run the applications
without recompiling.

It would be appreciated if anyone could help me out on
this count.

Thanks in advance.
 
The launching process really controls the location (and name) of the default
configuration file. Having said that, you have a couple of options:
1) Create a configuration section reader, and have users add specific
entries into their existing configuration files. This is what WSE does.
2) Ask users to create a [mycomponentname].config file, and just use one of
the XML classes (XmlDocument, XPathDocument, XmlTextReader) to acquire the
configuration info. Optionally, set up a watch on the file so that you can
detect when the file is updated. This is essentially what ASP.NET does with
web.config files.
 
I'm working on a .NET component library and I need to
have a config file to be used by the library components.
But as a newcomer to the .NET technology, I don't know
where and how to start.

Well, have a look at the System.Configuration namespace - it defines
the standard (XML-based) .NET config files, and how to use them.

Unfortunately, by default, these are only for applications (EXE's) -
not libraries / assemblies (DLLs). However, the 'net is your friend,
and there are lots of third-party solutions out there already, that
will allow you to have a MyLibrary.dll.config file, and make use of
it, too.

Have a look at this one, for example - there are more on CodeProject
and other sites:

http://www.codeproject.com/csharp/Custom_Config_File_Reader.asp

Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Back
Top