Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommend classes for handling xml configuration file in C#? [closed]

I am writing a program that need to store some configuration information. I thought XML would be a good choice, but I do not want to learn XML in C# from scratch.

Could you recommend good ways/classes handling this task?

like image 404
Jichao Avatar asked Oct 19 '10 04:10

Jichao


2 Answers

Just use the built-in .NET configuration system! What's wrong with that??

For that, add a reference to System.Configuration to your project, and have a good look at the ConfigurationManager class in that namespace.

  • MSDN docs on the System.Configuration namespace
  • MSDN docs on the ConfigurationManager class
  • Using Application Configuration Files in .NET
  • Specifying Configuration Settings in Web.config

Starting with Visual Studio 2005, you can also define application- or user-scoped settings in a visual designer inside VS - check out Application Settings Overview on MSDN for this (those work for Winforms and console apps). Those settings are stored in your app.config/web.config for the application-scoped settings, and in a separate user.config file in a directory accessible to the user account for the user-scoped settings. Those can be manipulated and updated at runtime using standard .NET classes (from the System.Configuration namespace).

like image 64
marc_s Avatar answered Sep 28 '22 00:09

marc_s


While I agree that "re-inventing the wheel" is not a good idea, the .NET System.Configuration class is abominably difficult to use for such a simple task.

I needed to create separate configuration files that could be specified on the command line for one of my programs (instead of just default assuming it would be "app.config") so I used this simple class - which saves itself to an XML file.

http://www.dot-dash-dot.com/files/UIsettings.vb

like image 20
Ron Savage Avatar answered Sep 28 '22 00:09

Ron Savage