more values in one section of app.config

  • Thread starter Thread starter Patrick
  • Start date Start date
P

Patrick

Hi

I want tu use an app.config like the example below. The problem is, that i
don't know how many Action-Tags there will be, because this can be changed
by the user. When using
System.Configuration.ConfigurationSettings.GetConfig("IncomingActions/action
") I can access the config file, but get only the values of the Last
Action-Tag.


Does someone know, how to implement that using the app.config file?

Thanks

Patrick





<configSections>

<sectionGroup name="IncomingActions">

<section name="action"
type="System.Configuration.SingleTagSectionHandler" />

</sectionGroup>

</configSections>

<IncomingActions>

<action From="Value11" Message="value two1" Command="third value1"
Confirm="y" />

<action From="Value21" Message="value two2" Command="third value2"
Confirm="y" />

<action From="Value31" Message="value two3" Command="third value3"
Confirm="y" />

<action From="Value41" Message="value two4" Command="third value4"
Confirm="y" />

</IncomingActions>
 
Hi Patrick,

I would suggest you put those config settings in another XML file, so you
can parse it and create a collection ( or maybe a Hashtable ) to contain
them.
You can create a class Config with a static constructor ( to be sure it will
be called before you use this class ) from where you load/parse the config.

Then you can have properties ( I suggest static too ) that you have access
to the settings.


Hope this help,
 
Patrick,
In addition to Ignacio's suggestion of creating "another XML" file.

You can actually do this with a single XML file the app.config itself.

The trick is, instead of defining IncomingActions as a sectionGroup with a
nested SingleTagSectinoHandler. You define IncomingActions as a custom
Configuration Section Handler. You do this by implementing the
System.Configuration.IConfigurationSectionHandler interface, then using the
XML dom parse the XML Node.

I would have the IncomingActions handler return a collection of Action
objects.

I do not have a link to a handy sample right now. If you need one post and I
will try to find the links to the two or three I found earlier.

Hope this helps
Jay
 
Hi

Instead of defining you section type as :
type="System.Configuration.SingleTagSectionHandler


use the following :
type="System.Configuration.NameValueSectionHandler

Then use the getCongig function that return a
NameValueColection an all value will be then retrive from
the section.

U can then browse the desired item of the collection and
process accordingly.

That works really fine, I am doing it like that for my app
config file whcih have different section group

regards
serge
 
so there is no way to make this with the usual config stuff.... for the
other i have already my own xml-config reader, for complexer settings, but
okay, thanks for that hint
 
Back
Top