views:

252

answers:

3

Hi,

I'm building a processing system, and I would like to configure it using an XML.
What technology should I use?, I have a lot of options:
1] I can serilize a dumy object into xml, change the content and then load it every time I run the app. I'v implemented this, because you don't have to write a lot of code to make this work, but It's a very dirty process. So I'm currently unhapppy.
2] You can use a XElement to read XMLs, just pass one to the constructer and let it build itself from that. 3] Use the .NET application settings architecture. <- I don't really undstand how this works yet.

I want the code to be simple and stupid, and to allow the code to change the config file for example, change the date of the last successful event.

Anyways if you can point me to useful places, and give me some direction, I'd really appreciate it.

Cheers.

A: 

Use the .NET application settings architecture. its really simple.

Woland
+3  A: 

.NET Application Settings is the way to go.

Doubleclick on properties in your Visual Studio project. Choose 'Settings' and add a new settings file.

Depending on your desired features you can choose a setting to be in the 'application' scope or in the 'user' scope:

User
Advantage: configurable from the application itself.

Application
Advantage: configurable from the app.config file in your application's folder

So save all the settings you want to edit in xml, in the Application scope. And save the LastSuccessfulEvent in your User scope.

You can retrieve your settings from the Properties.Settings.Default class.


Make sure that when you change a setting from code, to call the Save() function.

Settings.Default.LastSuccessfulEvent = "NewValue";
Settings.Default.Save();
Jan Jongboom
I just started to use app.config and this was helpful, but it doesn't say anything about how Application settings don't seem to take effect in your application unless you go back to the Settings tab in your Project Properties dialog and then recompile. This question happens to address this behavior: http://stackoverflow.com/questions/473028/how-to-edit-application-configuration-settings-app-config-best-way-to-go
Dave
A: 

The easy and correct way to do it would be indeed to use the settings files. You can add as many as you need and insert whatever configurations. Here's and example about how it's used. Let me now if you'll need more examples and tutorials.

Adrian Faciu