views:

1016

answers:

5

Hey, I want to store application configuration data. Currently, I'm using INIs but they are too old and now I want to try something new. I'm on .NET platform using C#.

What solutions do I have? app.configs?

The scenario here is like that, I want to let other programs read the configuration data.

+5  A: 

Yes, the various .config files (app.config, web.config, etc..) have replaced INI and, to a certain extent, the Registry as the preferred means of storing configuration data for your application.

Any program, .Net or otherwise, can read those files. .Net has the ConfigurationManager class and other languages can simply do XML parsing to get the values they need.

Chris Lively
Also, search for "the last custom configuration section handler you'll ever need". It provides general-purpose code to handle "custom" data in the .config file. This is called a "custom config section handler" in .NET parlance, and Craig Andera originally wrote a general one, which is very re-usable. A number of people have then extended it. Eg, http://weblogs.asp.net/sweinstein/archive/2005/01/10/350299.aspx . But search for others to see what I mean.
Cheeso
+1  A: 

The standard approach with .NET is to use app.config files for application settings and user.config files for user specific settings (the location varies between XP and Vista though).

There's nothing to stop other programs reading the configuration data, you just need to have a configuration setting in the second (or third) application that tells it where to look.

ChrisF
+1  A: 

The app.config would be the preferred way of doing things in .NET. Should work fine to read from other applications as well, as long as you give them the right path to the file. And it's just an XML file, so you can read it from non .NET apps as well.

tomlog
+1  A: 

If you're using Visual Studio, you can use Application Settings for this purpose. Just open the automatically added Settings.settings or create another one. They will be automatically available in Properties.Settings.Default and are stored as XML. You can also have multiple settings files for different purposes.

This is a Visual Studio concept rather than a .NET concept.

OregonGhost
A: 

I often use an SQL table to hold my application settings. I create a singleton class, ususally called AppSettings, that I load with data from the table. The AppSettings class is then used to get the config values instead of directly accessing the config files. For ASP.Net apps, I instantiate the AppSettings class in the Application_Start event in Global.asax.cs.

Doing this gives me a way to allow the user to control some of the app settings, e.g. an email address for notifications. It also can simplify things when maintaining prod, QA, and dev versions of the app (assuming you have separate database instances for each)

Mike K.