Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to query App.config? 2

Status
Not open for further replies.

EwS

Programmer
Dec 30, 2002
398
US
Here's my App.config file:
Code:
<?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.
 
I would advise against using the App.Config file to store this kind of data. Put the info into a DataSet, and use .WriteXML to save the data to an XML file and .ReadXML to retrieve the data.



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Agreed. There is a FAQ here: that shows the code for an XML based INI file that uses the user's data storage folder.

IMO, the App.Config file should never be used for anything that will change, passwords, server names, etc... Many network admins lock down the C: so that only admins can install software. If that C: is locked, and you are trying to alter the App.Config, you're going to have a very hard go at it. Thus the reason for storing user settings and any dynamic application information in a separate file in a location that you are guarantied to have write access.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top