473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

app.config file

Hi, I am using the app.config file to store the ConnectionString to the data.
I want to add a list of table names to this file so I could populate a combo
on FormLoad.
I found very easy to get the ConnectionString using the
ConfigurationManager.ConnectionStrings("name"), whoever I could not find any
examples of adding a list of values to the config file and retreaving it.
Could someone give a hand or an example.
Nov 3 '06 #1
5 1356
Try using an "appSettings" section:

http://msdn.microsoft.com/library/de...ngsElement.asp
http://msdn2.microsoft.com/en-us/lib...54(VS.80).aspx
http://msdn2.microsoft.com/en-us/lib...gs(VS.80).aspx
http://msdn2.microsoft.com/en-us/lib...12(VS.80).aspx

--
HTH,

Kevin Spencer
Microsoft MVP
Ministry of Software Development
http://unclechutney.blogspot.com

I just flew in from Chicago with
a man with a wooden leg named Smith
who shot an elephant in my pajamas.
So I bit him.
"HLong" <HL***@discussions.microsoft.comwrote in message
news:CB**********************************@microsof t.com...
Hi, I am using the app.config file to store the ConnectionString to the
data.
I want to add a list of table names to this file so I could populate a
combo
on FormLoad.
I found very easy to get the ConnectionString using the
ConfigurationManager.ConnectionStrings("name"), whoever I could not find
any
examples of adding a list of values to the config file and retreaving it.
Could someone give a hand or an example.

Nov 3 '06 #2
You could store the items as a string separated by semi-colons. When reading
it back, you split the string and add the items to the combobox with
AddRange. Something like:

Save:

string s = ""; // use StringBuilder for better performance
foreach (string t in comboBox1.Items)
if (t != "")
s = s + t + ";";
ConfigurationManager.AppSettings["Items"] = s;

Load:

string[] ss =
ConfigurationManager.AppSettings["Items"].Split(new char[] { ';' });
comboBox1.Items.Clear();
comboBox1.Items.AddRange(ss);
--
Regards, Peter
Nov 4 '06 #3
Thanks to both Kevin and Peter for your help. Is it possible to add a custom
section something like

<test>
<add key="test1" value="Somevalue"
<add key="test2" value="Somevalue2"
</test>

and then, retriving it using the configmanager?
Nov 6 '06 #4
It is, but it's a bit complicated.

Here's an article that can help you get started:

http://www.codeproject.com/dotnet/cu...ctionsNet2.asp

--
HTH,

Kevin Spencer
Microsoft MVP
Ministry of Software Development
http://unclechutney.blogspot.com

I just flew in from Chicago with
a man with a wooden leg named Smith
who shot an elephant in my pajamas.
So I bit him.
"HLong" <HL***@discussions.microsoft.comwrote in message
news:8C**********************************@microsof t.com...
Thanks to both Kevin and Peter for your help. Is it possible to add a
custom
section something like

<test>
<add key="test1" value="Somevalue"
<add key="test2" value="Somevalue2"
</test>

and then, retriving it using the configmanager?

Nov 6 '06 #5
You can add strings you don't want to hardcode to the Resources. This can
be done easily by double-clicking on the project to bring up the properties,
and clicking on the <Resourcestab.

You can retrieve anything you store in here using
My.Resources.NameYouGaveIt,
where NameYouGaveIt is what you called it.

This is handy for storing stuff like messagebox strings you use a lot. I use
it to store
report headings with my company name on it, and disclosure statements that
get
printed on the bottom of reports, because they tend to change, and this way
I
only have to change them in one place.

If you're programming in C#, I'm sure there's some way to get to those
Resource
strings, but I don't know what it is.

Good luck.
Robin S.
-----------------------------------------------
"HLong" <HL***@discussions.microsoft.comwrote in message
news:CB**********************************@microsof t.com...
Hi, I am using the app.config file to store the ConnectionString to the
data.
I want to add a list of table names to this file so I could populate a
combo
on FormLoad.
I found very easy to get the ConnectionString using the
ConfigurationManager.ConnectionStrings("name"), whoever I could not find
any
examples of adding a list of values to the config file and retreaving it.
Could someone give a hand or an example.

Nov 7 '06 #6

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

Similar topics

13
by: Maxim Khesin | last post by:
I want to have a config file with my python proggie, satisfying the following requirements: 1) support key->(value, default) 2) simple and intuitive to read and edit 3) easyly readable into a...
4
by: Fuzzyman | last post by:
There have been a couple of config file 'systems' announced recently, that focus on building more powerful and complex configuration files. ConfigObj is a module to enable you to much more *simply*...
2
by: Suresh Gladstone | last post by:
Hi, This is a bit with versioning and installation of the .NET dlls. I want to perform the following, 1. A third party application will be invoking my .NET dll through COM interop . For this I...
4
by: grs | last post by:
Can a class library have a app.config file. Reason for asking is that the microsoft application blocks all read from myApp.exe.config. How can you use the application blocks if you do not have an...
22
by: Daniel Billingsley | last post by:
Ok, I wanted to ask this separate from nospam's ridiculous thread in hopes it could get some honest attention. VB6 had a some simple and fast mechanisms for retrieving values from basic text...
6
by: Rich | last post by:
Hello, I picked up this example on using the Reflection namespace for loading forms/classes on the fly at msdn http://msdn.microsoft.com/library/default.asp?...
13
by: Khodr | last post by:
Hello, I am using VS.NET 2003 and vb. I build my application MyApp and it generates MyApp.exe.config. So now MyApp.exe reads parameters from MyApp.exe.config. Great and no problem! I need to...
3
by: Blasting Cap | last post by:
I am working on a web app that I want to be able to use a separate config file on, in addition to the web.config file that's already working in the application. If I put the following in the...
12
by: dbuchanan | last post by:
Hello, (Is this the proper newsgroup?) === Background === I am building a solution with two projects. One project is my data access layer which contains my DataSet as an xsd file. The XSD...
5
by: mmcd79 | last post by:
I built a VB.net application that makes use of a machine level DB connection string setting, and a user level starting location setting. The machine level setting and the default user based...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.