473,802 Members | 1,937 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

config files - how to avoid clutter?

Many of an app's classes could read the config file. The config file could
contain many elements, and it will be difficult to know which config file
entry belongs to which class. I could adopt a naming scheme for the
elements. But am I limited to using the <appSettings> element for my
settings? It would be good to have elements such as <myClass1Stuf f> so that
it's easy to tell which settings go with each class. But whether I put
<myClass1Stuf f> in the <configuratio n> element or the <appSettings> element,
I receive configuration errors. Does anyone have good ideas/suggestions for
keeping the configuration entries manageable? Thanks!
Jul 19 '05 #1
1 1639
Marty,
Go ahead and create a section new sections in the app.config file.

There is a predefined configSections section in the app.config that you use
to define new sections.

Something like:

<configuratio n>

<configSections >
<section name="myClass1S tuff"
type="System.Co nfiguration.Dic tionarySectionH andler, System" />
<sectionGroup name="environme nts">
<section name="productio n"
type="System.Co nfiguration.Sin gleTagSectionHa ndler, System" />
<section name="developme nt"
type="System.Co nfiguration.Sin gleTagSectionHa ndler, System" />
</sectionGroup>
</configSections>

<appSettings>
<add key="key1" value="value1" />
<add key="environmen t" value="producti on" />
</appSettings>

<myClass1Stuf f>
<add key="key1" value="value1" />
</myClass1Stuff>

<environments >
<production value1="xyz" value2="abc" value3="edf" value4="ghi" />
<development value1="xyz" value2="abc" value3="edf" value4="ghi" />
</environments>

</configuration>

If you inherit from DictionarySecti onHandler you can easily change the key
or value in your section. I've derived from DictionarySecti onHandler to
change key/value to plugin/type in a few of my projects.

I use the above environments section to define each of my environments,
Production, QA, Test, Development. Where each environment points to the
correct database servers, web servers, message queues, printers any 'per
environment' settings. The appSettings/environment setting is used to
identify the current environment in use.

You then need to use System.Configur ation.Configura tionSettings.Ge tConfig to
get your section, which returns an object based on the type of section
handler defined for that section (usually HashTable, but can be other object
types.

See the following on how to create new sections via the configSections
section.

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

and:
http://msdn.microsoft.com/library/de...ionsschema.asp

Also read about the System.Configur ation.Configura tionSettings class and
other classes in the System.Configur ation namespace.

Hope this helps
Jay

"Marty McDonald" <mc******@wsdot .wa.gov> wrote in message
news:OU******** ******@TK2MSFTN GP10.phx.gbl...
Many of an app's classes could read the config file. The config file could contain many elements, and it will be difficult to know which config file
entry belongs to which class. I could adopt a naming scheme for the
elements. But am I limited to using the <appSettings> element for my
settings? It would be good to have elements such as <myClass1Stuf f> so that it's easy to tell which settings go with each class. But whether I put
<myClass1Stuf f> in the <configuratio n> element or the <appSettings> element, I receive configuration errors. Does anyone have good ideas/suggestions for keeping the configuration entries manageable? Thanks!

Jul 19 '05 #2

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

Similar topics

16
16463
by: Frank Oquendo | last post by:
ConfigurationSettings.AppSettings allows me to read from my config but how do I write to my config file? -- There are 10 kinds of people. Those who understand binary and those who don't. http://code.acadx.com (Pull the pin to reply)
5
10537
by: BPearson | last post by:
Hello I would like to have several sites share a single web.config file. To accomplish this, I would point the root of these sites to the same folder. Is there any reason why I might not want to do this? (IIS 5 or 6 In case you're wondering why I would do this, we have many web sites on a single server, and there are groups of sites that need to share common configuration information. I'd like to ease some administration by having one...
7
3351
by: Bob | last post by:
It's great that VS.NET makes it so effortless to add a web reference to a web service. The problem is, I haven't figured out a way to configure the URLs (or simply switch the references to another web reference) easily when I move my app from development, to staging, to production, as I have corresponding environments for the web services too. So far what I have done is copying the Reference.cs file out and creating a separate class by...
9
6479
by: Benny Ng | last post by:
Hi,all, How to let the sub-directory to avoid the authentication control from Root's webconfig? I heard that we can add a new web.config to the sub-directory. And then we can slove the problem. Virtual directory is £ºhttp://localhost/main Sub-directory is : http://localhost/main/reminder
1
249
by: Marty McDonald | last post by:
Many of an app's classes could read the config file. The config file could contain many elements, and it will be difficult to know which config file entry belongs to which class. I could adopt a naming scheme for the elements. But am I limited to using the <appSettings> element for my settings? It would be good to have elements such as <myClass1Stuff> so that it's easy to tell which settings go with each class. But whether I put...
0
1021
by: marfi95 | last post by:
I have 2 questions. First a little background. I have an app that is used by my entire team to parse files and some other stuff that we normally do during the day. This app is driven very heavily by the options defined in my EXE.APP.CONFIG file. The way I deliver updates to my users is by placing the exe and exe.config on a shared drive. Then I load the assembly from the shared drive to see if a newer version exists or not. If so, the...
2
1635
by: OO | last post by:
Hi all, OK loads of posts on here about developers trying to use an app.config for a dll class library. Of course I would normally say the config file is down to the app domain of the application calling your class library: a web app or an exe. However....in my case, I need to call this class library from vbscript for some legacy applications and so I do not have an Xml config file. I am happy to create a class which I use to hold my...
0
1322
by: Willy Van den Driessche | last post by:
I put my datasets inside a DLL (I have moved them out of app_code to avoid the clutter). These are typed datasets for which the code is generated by dotnet. To be able to generate them I have found little else than to add a "setting" to my DLL. How can I configure them to read their settings from the main app's web.config instead of the my.settings.... infrastructure ? I can of course add code to these partial classes and initialize...
3
2291
by: =?Utf-8?B?RHVrZSAoQU4yNDcp?= | last post by:
I've added a web deployment project and want to use the config section replacement but I'm obviously not understanding something. I have set up an alternate appSettings file, test.appSettings.config, and when I build the appSettings are correctly overridden, but I also end up with a copy of test.appSettings.config in my web site. If I have config sections for several environments they all get copied. How do I stop the copy? I wondered...
0
9699
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10538
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10285
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10063
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7598
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6838
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4270
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
3
2966
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.