ConfigurationSection with duplicate keys?

G

Guest

I'm trying to setup a email info config section like:
<contactForm>
<email>
<add key="toaddress" value="(e-mail address removed);" />
<add key="toaddress" value="(e-mail address removed);" />
<add key="toaddress" value="(e-mail address removed);" />
<add key="subjectprefix" value="website contact: " />
<add key="smtphost" value="mail.myhost.com" />
<add key="greeting" value="Please feel free to send us your
questions or comments." />
</email>
</contactForm>

the multiple toaddress fields would change in number depending on wether I'm
testing a new page and sending results to administrators etc.
the toaddress field is used to create a MailAddress object for adding to a
MailMessage.
or maybe I need nested tags?
<contactForm>
<email>
<addresses>
<add key="toaddress" value="(e-mail address removed);" />
<add key="toaddress" value="(e-mail address removed);" />
<add key="toaddress" value="(e-mail address removed);" />
</addresses>
....
Any code samples or links would be appreciated, not sure what class to use
for the ConfigSection handler so it creates a collection of toaddresses.

Thanks for any ideas!
 
S

sloan

Using the "key" name is an approach (which you're probably trying to mimick
the AppSettings in the app or web config files.

http://spaces.msn.com/sholliday/ 2/8/2006 entry

I have a custom configuration handler there if you want to look at it.

If it were me, I go with
<contactForm>
<email>
<addresses>
<address value="(e-mail address removed);" />
<address value="(e-mail address removed);" />
</addresses>
</email>
</contactForm>

I wouldn't try to perfectly mimick the microsoft appsettings way... because
they're creating a NamedValueCollection... in a generic fashion.

You know what you're after. Which are 1:N email addresses.
 
G

Guest

One easy way to do this without dealing with custom configSection handlers:

<appSettings>
<add key="emailAddresses" value="(e-mail address removed);[email protected];[email protected]" />
</appSettings>

in your code:

string[] emailAddresses =
ConfigurationManager.AppSettings["emailAddresses"].Split(';');

Peter
 
G

Guest

Clever! Thanks.

Peter Bromberg said:
One easy way to do this without dealing with custom configSection handlers:

<appSettings>
<add key="emailAddresses" value="(e-mail address removed);[email protected];[email protected]" />
</appSettings>

in your code:

string[] emailAddresses =
ConfigurationManager.AppSettings["emailAddresses"].Split(';');

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Dabbler said:
I'm trying to setup a email info config section like:
<contactForm>
<email>
<add key="toaddress" value="(e-mail address removed);" />
<add key="toaddress" value="(e-mail address removed);" />
<add key="toaddress" value="(e-mail address removed);" />
<add key="subjectprefix" value="website contact: " />
<add key="smtphost" value="mail.myhost.com" />
<add key="greeting" value="Please feel free to send us your
questions or comments." />
</email>
</contactForm>

the multiple toaddress fields would change in number depending on wether I'm
testing a new page and sending results to administrators etc.
the toaddress field is used to create a MailAddress object for adding to a
MailMessage.
or maybe I need nested tags?
<contactForm>
<email>
<addresses>
<add key="toaddress" value="(e-mail address removed);" />
<add key="toaddress" value="(e-mail address removed);" />
<add key="toaddress" value="(e-mail address removed);" />
</addresses>
...
Any code samples or links would be appreciated, not sure what class to use
for the ConfigSection handler so it creates a collection of toaddresses.

Thanks for any ideas!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top