How to query App.config?

G

Guest

Here's my App.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="customers">
<section name="test1"
type="System.Configuration.DictionarySectionHandler" />
<section name="test2"
type="System.Configuration.DictionarySectionHandler" />
</sectionGroup>
</configSections>

<appSettings>
<add key="ConnectionString" value="some value here" />
</appSettings>

<customers>
<test1>
<add key="CustCode" value="0001" />
<add key="FtpHost" value="ftp://xxx.com" />
<add key="FtpAccount" value="user1" />
<add key="FtpPassword" value="password1" />
<add key="Active" value="Y" />
</test1>
<test2>
<add key="CustCode" value="0002" />
<add key="FtpHost" value="ftp://yyy.com" />
<add key="FtpAccount" value="user2" />
<add key="FtpPassword" value="password2" />
<add key="Active" value="Y" />
</test2>
</customers>
</configuration>

If I know the 'CustCode' value (such as "0001"), how can I retrieve all the
other values for 'test1'?
I appreciate your help! Thank you.
 
M

Mr. Arnold

If I know the 'CustCode' value (such as "0001"), how can I retrieve all
the
other values for 'test1'?
I appreciate your help! Thank you.

You use the ConfigurationManger namespace that comes with .Net Framework
2.0, or you install the Application Blocks for .Net Framework 1.1 which uses
the ConfigurationSettings namespace.

This link talks about ConfigurationManager for .Net Framework 2.0.

http://www.eggheadcafe.com/articles/20060622.asp

If you using .Net Framework 2.0, then the only thing you're doing is
downloading the examples and code on how to use ConfigurationManager, which
there will be examples in VB and C#.Net. There is nothing to install.

http://www.google.com/search?hl=en&...cks+for+.Net+framework+2.0&btnG=Google+Search

If you are using .Net Framework 1.1, then you have to download and install
the Enterprise Library for Application Blocks. which will have examples in
VB and C# .Net too.

With .NET FW 2.0, you just set reference to the dll for Configuration
Manager, and for .NET FW 1.0, you have to determine which dll in the
Enterprise Library you must use and set reference to it or them. There is
nothing to compile as the dll(s) have the code that's needed. You just use
the dll(s).

In either case for 2.0 or 1.0 with Application Blocks examples in VB or
C#.Net, you will see one example on how to pull the elements of the XML
App.Config file into your program so that you can use the values of the
elements.

It's a piece of cake, and it should be no problem for you to do what you
want. You can also use Google to see the how-to(s) as well.
 

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