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

  • Thread starter Thirsty Traveler
  • Start date
T

Thirsty Traveler

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>
 
G

Guest

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(';');
 
T

Thirsty Traveler

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 said:
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 said:
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>
 

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

Top