Fill a listbox with app.config data

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm just starting out with C# after many years with VB 6.0.

I'm trying to fill a listbox with a list of computer names (almost 100) from
app.config. First, is app.config the place to store and retrieve this large
list?

If so, I'm looking for code to obtain the list of computer names from
app.config, and also an example of how the computer names need to be listed
in app.config.

Thanks,
 
Hi WB,

I'm would probably have stored the list in a (comma)separate(d) file instead of App.config.
To read the file you could use

string data File.ReadAll(filename);
string[] names = data.Split(',');
 
I should correct myself

string[] names = File.ReadAllLines(filename);


Hi WB,

I'm would probably have stored the list in a (comma)separate(d) file instead of App.config.
To read the file you could use

string data File.ReadAll(filename);
string[] names = data.Split(',');


I'm just starting out with C# after many years with VB 6.0.

I'm trying to fill a listbox with a list of computer names (almost 100) from
app.config. First, is app.config the place to store and retrieve thislarge
list?

If so, I'm looking for code to obtain the list of computer names from
app.config, and also an example of how the computer names need to be listed
in app.config.

Thanks,
 
Bill,

I would not store this list in app/settings. Especially the comma delimited
route.

There are a couple of options that I have done:

I usually put a list, which only changes every blue moon its its own little
xml file.
Since you're new to dotNet, do a search for "Strong typed DataSet".
This will allow you to call methods like .WriteXml and LoadXml( string
fileName ).
What I'm saying is that you can store it in a small xml file , and if you
piggy back off your custom strongly typed dataset, you can use those easy to
use methods, especially the LoadXml one.

Secondly, you can write you own "Custom Configuration Handler", and add some
xml to the existing app.config (or web.config) file.


<mystuff>
<state name="Virginia" abbv="VA" />
<state name="North Carolina" abbv="NC" />
<state name="Tennesee" abbv="TN" />
</mystuff>

but it takes some coding/work to get this working. However, learning how to
write a custom config handler is a very good base skill.

go and google this
http://www.google.com/search?hl=en&lr=&q=custom+configuration+section
http://support.microsoft.com/kb/309045/EN-US/

There are multiple options, somebody will post another probably. But those
2 have served me well.

But littering up the app/settings is kinda hacky in my book.
 
Ya, I don't think you should store you data in app.config too. As the name
implied it is for your application configuration. You really should think of
XML or database and worst come to worst a text file.

chanmm
 

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

Back
Top