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

What is the best way to populate an array from a config file.

P: n/a
I have an application that will be accessing an array of ports obtained from
a config file. What would be the best way to do populate the array if the
config file has, say, the following format:

<configuration>
<applicationSettings>
<AppURL server=http://DevAppServer>
<port value="8000"/>
<port value="8100"/>
<port value="8200"/>
</AppURL>
</applicationSettings>
</configuration>
Jun 5 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I don't believe that will work for appSettings, because you have multiple
identical key names.

You could do
<port values="8000;8100;8200;8300"/>

Then in your code,

string[] portValues ConfigurationSettings.AppSettings["port"].Split(';');
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Thirsty Traveler" wrote:
I have an application that will be accessing an array of ports obtained from
a config file. What would be the best way to do populate the array if the
config file has, say, the following format:

<configuration>
<applicationSettings>
<AppURL server=http://DevAppServer>
<port value="8000"/>
<port value="8100"/>
<port value="8200"/>
</AppURL>
</applicationSettings>
</configuration>

Jun 5 '06 #2

P: n/a
Actually, I was concerned about this in AppSettings as well (which I usually
use for config strings), so I put it into applicationSettings.

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:28**********************************@microsof t.com...
I don't believe that will work for appSettings, because you have multiple
identical key names.

You could do
<port values="8000;8100;8200;8300"/>

Then in your code,

string[] portValues ConfigurationSettings.AppSettings["port"].Split(';');
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Thirsty Traveler" wrote:
I have an application that will be accessing an array of ports obtained
from
a config file. What would be the best way to do populate the array if the
config file has, say, the following format:

<configuration>
<applicationSettings>
<AppURL server=http://DevAppServer>
<port value="8000"/>
<port value="8100"/>
<port value="8200"/>
</AppURL>
</applicationSettings>
</configuration>

Jun 5 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.