By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,117 Members | 1,714 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,117 IT Pros & Developers. It's quick & easy.

.NET 2.0 Configuration

P: n/a
Any suggestions on how you can load an arbitrary number of unknown
attributes on an element in a custom section in the .config into a
NameValueCollection ?

Basically I want to do something similiar to what occurs with a
System.Configuration.Provider.ProviderBase Initialise method - the provider
is passed a NameValueCollection containing attribute names and their
associated values from the .config. see...

http://msdn2.microsoft.com/en-us/lib...nitialize.aspx

All the examples I've seen with the .NET 2.0 config api deal with scenarios
where the attributes are predefined and loaded using static code.

One brute force solution that comes to mind is just to by-pass the
Configuration api and use XML/DOM to parse the web config . But if there's
a more elegant solution that leverages the .NET Config API I'd like to use
it.

Thanks in advance

Michael
Jan 23 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
What you need to do is to create your own configuration classes which can be
used in conjuntion with your configuration file. The .Net 2.0 Configuration
object model is incredibly extensible, allowing you to store any type of
data serialized in configuration files.

The System.Configuration Namespace is the location of all of these classes
(http://msdn2.microsoft.com/en-us/lib...guration.aspx). The
most salient ones are Configuration, ConfigurationManager,
ConfigurationElement, ConfigurationElementCollection, ConfigurationSection,
ConfigurationSectionCollection, ConfigurationSectionGroup, and
ConfigurationSectionGroupCollection. These are the classes that correspond
to the various XML elements in a Configuration file. Once you define your
classes, you can use them in any Configuration file.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

In case of Minimalism, break Philip Glass.

"Michael Lang" <micklang at gmail.comwrote in message
news:uf**************@TK2MSFTNGP04.phx.gbl...
Any suggestions on how you can load an arbitrary number of unknown
attributes on an element in a custom section in the .config into a
NameValueCollection ?

Basically I want to do something similiar to what occurs with a
System.Configuration.Provider.ProviderBase Initialise method - the
provider is passed a NameValueCollection containing attribute names and
their associated values from the .config. see...

http://msdn2.microsoft.com/en-us/lib...nitialize.aspx

All the examples I've seen with the .NET 2.0 config api deal with
scenarios where the attributes are predefined and loaded using static
code.

One brute force solution that comes to mind is just to by-pass the
Configuration api and use XML/DOM to parse the web config . But if
there's a more elegant solution that leverages the .NET Config API I'd
like to use it.

Thanks in advance

Michael

Jan 23 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.