C# – WinForms – which is easiest approach for persisting some data


Just building my first WinForms application.

Question – What's the easiest/best approach for saving some data between use of the application (e.g. list of URL with status & date/time in this case)? I don't see any need for a database.

For example
* Is just storing to text file easiest?
* Or is storing to XML file just as easy in DotNet
* How about Windows Registry – is this something generally to avoid? Is it's use compatible across all versions including Windows 7
* Database – probably overkill here
* A widely used library perhaps?


Best Solution

Storing to XML is very easy in .NET, particularly if you're really just storing a URL and a timestamp. You could create a custom class to hold the data... at runtime, manipulate instances of that class in your app.

When it's time to save, serialize the object(s) to XML... when the app needs to restore the data later, just deserialize. MSDN has a simple walkthrough.

It's worth noting, as Quintin did, that using SQL Server Compact or some other lightweight database might also be a good idea. XML's quick and easy - but if you need people to share data or you need anything more flexible than simple serialization, you're better off with a database.

Related Question