0

I would like to store a collection of strings in the web.config. This collection would vary in size over time. I would like to be able to pull all of the strings in the collection into an array or collection in code. (.Net 4, asp.net) i.e.

<customCodes>
<VendorCode vendorName="Name1" code="1234567891234567891324567987ddd" isActive="true"/>
<VendorCode vendorName="Name2" code="1sadfsadf1234567891324567987ddd"  isActive="true" />
<VendorCode vendorName="Name3" code="123456789dfadfdsaf3324567987d32"  isActive="true"/>
</customCodes>

I could use appsettings with the strings all in one value but I would like to seperate it out for organizational reasons.

Any code snippets or examples would be appreciated.

Sorry this was posted without the code example the first time. Not using the key/value pair complicates things a bit. I am now getting a message that states "you can't have duplicate elements in a section"

TIA J

1
  • 1
    You should really try to accept some of your old answers, or the community will not be as willing to help you.. Commented Aug 25, 2010 at 19:23

2 Answers 2

2

You can do this by creating a custom configuration section handler:

http://msdn.microsoft.com/en-us/library/2tw134k3.aspx

For collections have a look at the ConfigurationElementCollection

http://msdn.microsoft.com/en-us/library/system.configuration.configurationelementcollection.aspx

Following the second link a little deeper there is the code you need to to solve your problem. Just change somes tags and use "Add" instead of "VendorCode" :-)

http://msdn.microsoft.com/en-us/library/system.configuration.configurationcollectionattribute.aspx

Sign up to request clarification or add additional context in comments.

1 Comment

thanks both of the links have gotten me further down the path. The issue that I am running into now is that I keep getting an error about having the same parameter name in the web.config more than once.
0

The link http://dotnetslackers.com/articles/customconfiguration/Custom_Configuration_Collections.aspx was very helpful in accomplishing what I wanted to do. I did have to settle for using the "Add" tags instead of the custom tags that I origianally wanted.

Thanks for the help Dirk.

J

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.