473,405 Members | 2,310 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,405 software developers and data experts.

Complex configuration files

Hi all,
Have a look at this config file structure:

<appSettings>
<add key="connstr" value="workstation id=test;packet size=4096;user
id=sa;data source=test;persist security info=False;initial
catalog=test;password=test" />
</appSettings>
<mysettings>
<add key="intErrorLogtype" value="1" />
<add key="EventLogKeyName" value="FRISBEE" />
<add key="sys_DBCheck" value="usp_CheckSQLConnection" />
<add key="strCEPath" value="" />
</mysettings>

As you can see i have added a new element called <mysetting> that will
contain additional things that I want to store outside of the standard
appsettings tree.

How, in code, do I retrieve values from the section in my app.config
file under the section <mysettings>

thanks in advance for your help on this matter

Kerr

PS this is a VB.NET windows Forms application

*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #1
7 1730
Take a look at using configSections.

http://msdn.microsoft.com/library/de...ntainertag.asp

I love using them to keep my app.config files organized.

"Richard Kerr" <ri**********@guidestar.org.uk> wrote in message
news:up*************@TK2MSFTNGP12.phx.gbl...
Hi all,
Have a look at this config file structure:

<appSettings>
<add key="connstr" value="workstation id=test;packet size=4096;user
id=sa;data source=test;persist security info=False;initial
catalog=test;password=test" />
</appSettings>
<mysettings>
<add key="intErrorLogtype" value="1" />
<add key="EventLogKeyName" value="FRISBEE" />
<add key="sys_DBCheck" value="usp_CheckSQLConnection" />
<add key="strCEPath" value="" />
</mysettings>

As you can see i have added a new element called <mysetting> that will
contain additional things that I want to store outside of the standard
appsettings tree.

How, in code, do I retrieve values from the section in my app.config
file under the section <mysettings>

thanks in advance for your help on this matter

Kerr

PS this is a VB.NET windows Forms application

*** Sent via Developersdex http://www.developersdex.com ***

Nov 21 '05 #2

Ray,
Thanks for the speedy reply. I have a question for you. My first attempt
at doing this invovled creating configSections and then using the
following code to try and grab the value out of the app.config file.

Dim obj As IDictionary = _

CType(System.Configuration.ConfigurationSettings.G etConfig("sectionname"
),_
IDictionary)

However, this always returns nothing.

Is the implementation for configSections only available in asp.net
applications and not in windows forms?
*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #3
No, it works fine with Windows forms as well... here is a quick example of
one of my bits of code (from memory again):

Dim cfgLogLevels As NameValueCollection

cfgLogLevels = ConfigurationSettings.GetConfig("GEM_Log/LogLevels")
m_rootLevel = CType(cfgLogLevels.Get("Root"), Integer)
Here is the sample app.config file that goes with it:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="GEM_Log">
<section name="LogLevels"
type="System.Configuration.NameValueSectionHandler " />
</sectionGroup>
</configSections>
<GEM_Log>
<LogLevels>
<add key = "Root" value="5" />
</LogLevels>
</GEM_Log>
</configuration>

Hope this helps...

"Kerr" <ke*****@lycos.co.uk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...

Ray,
Thanks for the speedy reply. I have a question for you. My first attempt
at doing this invovled creating configSections and then using the
following code to try and grab the value out of the app.config file.

Dim obj As IDictionary = _

CType(System.Configuration.ConfigurationSettings.G etConfig("sectionname"
),_
IDictionary)

However, this always returns nothing.

Is the implementation for configSections only available in asp.net
applications and not in windows forms?
*** Sent via Developersdex http://www.developersdex.com ***

Nov 21 '05 #4
Ray,
Sorry for being a complete muppet but the namevaluecollection object you
have in code refers to the
system.Collections.Specialized.NameValueCollection right?

Well when i implement your code as you've defined the intellisense
throws an error saying cannot convert an namevaluecollection to an
object.

any ideas?
*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #5
Ray,
Please ignore my last post. That is not my problem. Your code does
work.

The problem i just discovered that I am having is that my app.config is
not attached to my Application project but to a dll project (Business
Logic) which is a separate project to the actual GUI. i.e.
App.exe (is standalone project)
Bl.dll (is standalane project)
DS.dll (is standalone project)

the app.config I am trying to read from is attched to the BL.dll and
when my app tries to look for this file it only check the app.exe. Thus
why nothing is being returned.

Not sure how to fix this but will keep on.

Cheers for your help in the matter anyway.

Kerr

*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #6
WERE THE FEMALES AT????

"Kerr" <ke*****@lycos.co.uk> wrote in message
news:eA**************@tk2msftngp13.phx.gbl...
Ray,
Sorry for being a complete muppet but the namevaluecollection object you
have in code refers to the
system.Collections.Specialized.NameValueCollection right?

Well when i implement your code as you've defined the intellisense
throws an error saying cannot convert an namevaluecollection to an
object.

any ideas?
*** Sent via Developersdex http://www.developersdex.com ***

Nov 21 '05 #7
That is normal. dll projects do not use their own config file. They use the
config file of the host exe assembly.

"Kerr" <ke*****@lycos.co.uk> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Ray,
Please ignore my last post. That is not my problem. Your code does
work.

The problem i just discovered that I am having is that my app.config is
not attached to my Application project but to a dll project (Business
Logic) which is a separate project to the actual GUI. i.e.
App.exe (is standalone project)
Bl.dll (is standalane project)
DS.dll (is standalone project)

the app.config I am trying to read from is attched to the BL.dll and
when my app tries to look for this file it only check the app.exe. Thus
why nothing is being returned.

Not sure how to fix this but will keep on.

Cheers for your help in the matter anyway.

Kerr

*** Sent via Developersdex http://www.developersdex.com ***

Nov 21 '05 #8

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

Similar topics

1
by: TT (Tom Tempelaere) | last post by:
Hey everyone, I'm currently writing software for a project that uses a lot of Xml files for configuration. The project is written in C#/.NET. Each such xml file has a schema defined for it (Xsd...
5
by: NoNickname | last post by:
Basically, how do I know that the release versions of all components are being published? The Build | Configuration Manager is confusing me a little in VS2005. I have three projects in my...
0
by: Umut Tezduyar | last post by:
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = "FactorySettings.config"; Configuration config =...
0
by: cyberstrike | last post by:
In the system.configuration namespace, is there any way to save a Dataset or any other custom structure in a section? I know how to make a class and derive it from the section class; however, any...
3
by: Ivan Berg | last post by:
Hey everyone, hopefully this will have a simple answer. Using VS2005/.NET 2.0 Application settings. I have simple settings working fine, but I am trying to store more complex types now. For...
0
by: metaperl | last post by:
A Comparison of Python Class Objects and Init Files for Program Configuration ============================================================================= Terrence Brannon bauhaus@metaperl.com...
9
by: KarlM | last post by:
After reading some articles regarding confuguration data I'm a bit confused. Where is the right place for storing configuration data? - XML-files? - registry? - INI-files? (from a users point...
7
by: Peter Bradley | last post by:
OK. A bit behind the times, I know; but we're just moving over to .NET 2.0. How on earth do you manage configuration settings in a class library in .NET 2.0? In version 1.1, we used a handy class...
3
by: Peter K | last post by:
Hi I need to be able to supply some relatively complex configuration to an application. The application will either run in a web context (with a web.config file, or as a application with an...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.