473,544 Members | 1,954 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieve a value from App.config

3 New Member
Here's my App.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<configSections >
<sectionGroup name="customers ">
<section name="test1"
type="System.Co nfiguration.Dic tionarySectionH andler" />
<section name="test2"
type="System.Co nfiguration.Dic tionarySectionH andler" />
</sectionGroup>
</configSections>

<appSettings>
<add key="Connection String" 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="FtpPasswor d" value="password 1" />
<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="FtpPasswor d" value="password 2" />
<add key="Active" value="Y" />
</test2>
</customers>
</configuration>

I'm trying to loop through customers group and retrieve the 'Active' key
value for each section (test1 and test2). The only way of doing this that I
found is use the Hashtable (see code below). The problem is that those key
values don't come in the order in which they are defined in the config file,
and I have to loop through all the keys until I find 'Active'. How can I
directly get the value I want? Thanks for any help!

Dim config As Configuration =
ConfigurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.None)
Dim custGroup As ConfigurationSe ctionGroup =
config.SectionG roups.Get("cust omers")

Dim custCodes As String = Nothing
For Each custNode As DefaultSection In custGroup.Secti ons
Dim cfg As Hashtable =
CType(Configura tionManager.Get Section(custNod e.SectionInform ation.SectionNa me), Hashtable)

Dim CustCode As String = Nothing
Dim FtpHost As String = Nothing
Dim FtpAccount As String = Nothing
Dim FtpPassword As String = Nothing
Dim Active As String = Nothing
For Each custAtt As System.Collecti ons.DictionaryE ntry In cfg
Select Case custAtt.Key
Case "CustCode"
CustCode = custAtt.Value
Case "FtpHost"
FtpHost = custAtt.Value
Case "FtpAccount "
FtpAccount = custAtt.Value
Case "FtpPasswor d"
FtpPassword = custAtt.Value
Case "Active"
Active = custAtt.Value
End Select
Next
Aug 17 '07 #1
3 5290
Plater
7,872 Recognized Expert Expert
Is that even a valid app.config format?
Aug 17 '07 #2
Eve DW
3 New Member
Of course it's a valid app.config format.

NOTE: You closed my other post because you thought I'm double posting - the thread starts the same, but at the end I asked a totally different question!! (PLEASE read carefully before closing a thread) - here was my question:

If I know the 'CustCode' value (such as "0001"), how can I retrieve all the
other values for 'test1'?

Since you closed my other thread, I'm not sure if I can get an answer to this question because it's hard to notice...


Is that even a valid app.config format?
Aug 17 '07 #3
CodeGeezer
1 New Member
here's a link that might be of help.
http://forums.microsof t.com/MSDN/ShowPost.aspx?P ostID=2343967&S iteID=1
it's basically working with the same type of nesting but it's a simplistic way of getting the app settings groups into an object to work with.
Oct 31 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1172
by: Anon | last post by:
I have an XML document that stores configuration settings for an app. I generated the schema using vs.net and also the corresponding dataset. I can load the config file (config.xml - below) and get all the data except for the element attribute values. I cannot figure out why the attribute values return a value of system.dbnull when the file...
5
3215
by: Robert Oschler | last post by:
I am converting a Perl script over to "C" for a potential open source project. I need some open source "C" code that will give me the same functionality of a Perl Style associative array: someArray = 6; I know I can't get the same syntactic sugar as Perl offers, with the usage of a string as the array key surrounded by square brackets. ...
5
18944
by: ad | last post by:
I have define some appsetings in ap.config like: <configuration> <appSettings> <add key="MailBody" value="Test Mail body"/> </appSettings> ..... I use
1
2820
by: toto | last post by:
Example: <configuration> <system.web> <httpRuntime maxRequestLength="2048" /> </system.web> </configuration> I need to kno in my code the value of key maxRequestLength. Thanks in advance.
6
5570
by: David Bowey | last post by:
Hi There! I'm writing a custom HttpHandler to create watermarks on my PNG images of my website. So typically, a PNG image is linked in an ASPX page as follows... <img src="images/test.png" alt="testing" /> So I created an HttpHanlder to handle PNG images, have mapped the PNG extension in the IIS and also added the HttpModule section in...
0
1666
by: george_Martinho | last post by:
It seems that the ASP.NET Microsoft team didn't think about this!! The profilemanager class has the following methods: - DeleteInactiveProfiles. Enables you to delete all profiles older than a specified date. - DeleteProfile. Enables you to delete a profile associated with a specified username. - DeleteProfiles. Enables you to delete a...
2
5486
by: Jon Paal | last post by:
..net 2.0 can't retrieve connection string from web.config, always returns error message -- what's missing ?? ======web.config ========= <appSettings> <connectionStrings> <add name="NorthwindConn" connectionString="Server='local'; database='NORTHWIND'; Trusted_Connection=False; uid=sa;pwd=*****"
7
2665
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file name based on the name of the VB6 application. A second choice would be a file name based on the # COM interface assembly. I have tried calling...
12
77945
lifeisgreat20009
by: lifeisgreat20009 | last post by:
I am a newbie to Struts and JSP...I have been working on the code below for 5 hours now..I googled a lot but couldn't get much help so finally I am here.. Hoping of getting my problem solved. Please give me some idea where I am going wrong ?? I just want to retrieve data from my emp_mstr table and display it using my JSP file... The table...
0
7420
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7362
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7704
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5904
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4911
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3407
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3404
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1837
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
657
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.