Search code examples
c#c#-3.0object-persistence

how to store data in c# application in a portable form?


I'm writing an application using windows form and c# 3.0. I was wondering if there is a recommended way of persist data across time. However, i do not want to touch the machine it is running on, as a result, i would like to store the data in the binary executable (preferably, due to the need not clutter up the user's folder with random config files).

So if anyone have any ideas of how to do this, it would be much appreciated!

Jason


Solution

  • If you're looking to store configuration information - app.config or a settings file is probably the way to go.

    If you are storing user data - you should really allow the user to control where it is saved - and prefer the \User\Username folder on the machine.

    As for what format to store it in ... you can certainly use something like SQLLite - but there's nothing wrong with XML either, if you're not storing true binary data. .NET offers a number of APIs to transform object graphs into XML representations - which you may want to look into.

    If you don't want to store anything on the local user's machine, you probably want a network database - or a webservice - to which you upload the users data. Just make sure your users understand this - many don't like their private data being sent somewhere on the web without their consent.

    You really don't want to go about modifying the executable file. Many virus scanners quarantine executables that are constantly changing in content or size - as a way to proactively prevent viruses and malware from infecting the machine. You don't want to go there.