473,509 Members | 2,890 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ConfigurationSection with duplicate keys?

I'm trying to setup a email info config section like:
<contactForm>
<email>
<add key="toaddress" value="he@hishost.com;" />
<add key="toaddress" value="sh*@herhost.com;" />
<add key="toaddress" value="it@itshost.com;" />
<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="he@hishost.com;" />
<add key="toaddress" value="sh*@herhost.com;" />
<add key="toaddress" value="it@itshost.com;" />
</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!
Apr 26 '06 #1
4 2940

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="he@hishost.com;" /> <address value="sh*@hishost.com;" />
<address value="th**@hishost.com;" />
</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.


"Dabbler" <Da*****@discussions.microsoft.com> wrote in message
news:9F**********************************@microsof t.com... I'm trying to setup a email info config section like:
<contactForm>
<email>
<add key="toaddress" value="he@hishost.com;" />
<add key="toaddress" value="sh*@herhost.com;" />
<add key="toaddress" value="it@itshost.com;" />
<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="he@hishost.com;" />
<add key="toaddress" value="sh*@herhost.com;" />
<add key="toaddress" value="it@itshost.com;" />
</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!

Apr 26 '06 #2
One easy way to do this without dealing with custom configSection handlers:

<appSettings>
<add key="emailAddresses" value="on*@my.com;tw*@my.com;th***@my.com" />
</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" wrote:
I'm trying to setup a email info config section like:
<contactForm>
<email>
<add key="toaddress" value="he@hishost.com;" />
<add key="toaddress" value="sh*@herhost.com;" />
<add key="toaddress" value="it@itshost.com;" />
<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="he@hishost.com;" />
<add key="toaddress" value="sh*@herhost.com;" />
<add key="toaddress" value="it@itshost.com;" />
</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!

Apr 26 '06 #3
Clever! Thanks.

"Peter Bromberg [C# MVP]" wrote:
One easy way to do this without dealing with custom configSection handlers:

<appSettings>
<add key="emailAddresses" value="on*@my.com;tw*@my.com;th***@my.com" />
</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" wrote:
I'm trying to setup a email info config section like:
<contactForm>
<email>
<add key="toaddress" value="he@hishost.com;" />
<add key="toaddress" value="sh*@herhost.com;" />
<add key="toaddress" value="it@itshost.com;" />
<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="he@hishost.com;" />
<add key="toaddress" value="sh*@herhost.com;" />
<add key="toaddress" value="it@itshost.com;" />
</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!

Apr 27 '06 #4
Sloan

Thanks for the code sample, That will do the trick!

"sloan" wrote:

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="he@hishost.com;" />

<address value="sh*@hishost.com;" />
<address value="th**@hishost.com;" />
</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.


"Dabbler" <Da*****@discussions.microsoft.com> wrote in message
news:9F**********************************@microsof t.com...
I'm trying to setup a email info config section like:
<contactForm>
<email>
<add key="toaddress" value="he@hishost.com;" />
<add key="toaddress" value="sh*@herhost.com;" />
<add key="toaddress" value="it@itshost.com;" />
<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="he@hishost.com;" />
<add key="toaddress" value="sh*@herhost.com;" />
<add key="toaddress" value="it@itshost.com;" />
</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!


Apr 27 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1488
by: anzenews | last post by:
Hello! I have a weird problem... The application I use issues this SQL from time to time: alter table t modify id int(6) unique not null auto_increment; The problem is that this SQL adds a...
3
13805
by: shine | last post by:
I am trying to add an integer array to a hashtable. While adding to hashtable I want to check the duplicates in array, the way I want to do is add the key(the integer stored in array) if a...
2
14113
by: gregory_may | last post by:
Anyone know how to create a sorted list with duplicate keys? The sorted list dies when you try and insert a duplicate key.
5
3975
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
2
13441
by: Rich | last post by:
Hello, I am just checking if there is a property or technique for displaying or retrieving from a dataTable the top 1 row(s) for rows containing duplicate keys (IDs). I have to pull data from a...
2
2524
by: Harry Haller | last post by:
I want to duplicate the form data, edit it to remove some items (such as __EVENTTARGET, __EVENTVALIDATION, etc) and save it to a log. How can I make a duplicate (editable) copy of the Form...
6
9001
by: reppisch | last post by:
Hi Ng, I have a multiset for keeping elements sorted in a container but key values may also be equal. Is there any guaranteed traversal order within the duplicate keys of a multimap? When...
1
7778
by: st12iker | last post by:
I managed to write a file to a hash. However the file contains multiple keys and value in the format listed. Note how the values are sorted in descending order. i.e. of file written to hash ...
2
5089
by: Smithers | last post by:
I have a Windows Forms application that implements a plug-in architecture whereby required assemblies are identified and loaded dynamically. Here are the relevant classes: A = application =...
1
1675
by: =?Utf-8?B?UGhpbGlw?= | last post by:
I am using the ConfigurationSection, ConfigurationElement, ConfigurationElementCollection base classes for purposes of reading a customized web.config Configuration section.....and I then use the...
0
7136
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7344
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7412
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
441
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.