views:

27

answers:

2

My application has historically used an ini file on the same file server as the data it consumes is located to store per user settings so that they roam if the user logs on from multiple computers. To do this we had a file that looked like:

[domain\username1]
value1=foo
value2=bar

[domain\username2]
value1=foo
value2=baz

For this release we're trying to migrate away from using ini files due to limitations in the win32 ini read/write functions without having to write a custom ini file parser.

I've looked at app.config and user settings files and neither appear to be suitable. The former needs to be in the same folder as the executable, and the latter doesn't provide any means to create new values at runtime.

Is there a built in option I'm missing, or is my best path to write a preferences class of my own and use the framework's XML serialization to write it out?

+1  A: 

I have found that the fastest way here is to just create an XML file that does what you want, then use XSD.exe to create a class and serialize the data. It is fast, and a few lines of code and works quite well.

Mitchel Sellers
That's the conclusion I was coming towards, but wanted to make sure I wasn't overlooking something hidden in a part of the framework I never looked at.
Dan Neely
A: 

Have you not checked out or have heard of nini which is a third party ini handler. I found it quite easy to use and simple in reading/writing to ini file.

For your benefit, it would mean very little changes, and easier to use.

The conversion from ini to another format needs to be weighed up, like the code impact, ease of programming (nitpicky aside, changing the code to use xml may be easy but it is limiting in that you cannot write to it). What would be the benefit in ripping out the ini codes and replace it with xml is a question you have to decide?

There may well be a knock on effect such as having to change it and adapt the code...but... for the for-seeable time, sure, ini is a bit outdated and old, but it is still in use, I cannot see Microsoft dropping the ini API support as it is very much alive and in use behind the scenes for driver installation...think of inf files used to specify where the drivers go and how is it installed...it is here to stay as the manufacturers of drivers have adopted it and is de-facto standard way of driver distribution...

Hope this helps, Best regards, Tom.

tommieb75
What do you mean by not being able to write xml? I've been reading/writing xml data files for years.
Dan Neely
@Dan: I just think Xml is overly complicated for a system settings hence the simplicity with ini, I mean, can you write to it at runtime to apply the changes via a configuration setting on the front end?
tommieb75