views:

340

answers:

6

Hi all,

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

+4  A: 

Do not modify the executable. Adding a single SQLite database is a much better solution.

Ignacio Vazquez-Abrams
A: 

SQLite is what your looking for and is compatible with c#

masfenix
+10  A: 

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.

LBushkin
+1 for "allow the user to control where user data is stored".
Dour High Arch
A: 

If you dont want to store data in a SQLite db on the end users PC you could call out to a web service on another server which stores it's data in SQL Server or something else.

Marc
A: 

I don't believe a windows form project can modify itself like that (I've tried to find a way to do this myself some time ago). Some form of hosted application such as a silverlight application (where the application is essentially a zip file) may be the way to go. Silverlight applications would require the silverlight plugin though (and I'm still not sure if a silverlight application is allowed to modify itself).

I would think that one config file of some sort would be prefereable, and not leave much clutter.

One way to ensure that your applicaiton is entirely self contained would be to use a program like ThinStall after you have compiled the project. This virtualises the application and could give it it's own file system or registry internally to the .exe file.

One way for an executable to change itself would be to put another executable inside it, (embed as a resource then extract it to a file when needed). This executable could then modify the first, however I don't think ther'es any framework for it to do that, so it would require knowing excatly what to change and where.

Tuskan360
+2  A: 

Isolated storage is another alternative.

  • Doesn't clutter install directory
  • Doesn't cause issues with AnitVirus software
  • Part of the OS including .Net objects, don't need to install anything else
  • Already works with the Windows security model
  • Exists on a per user basis, so saved settings are separated for each user
  • Can serialize/deserialize obects directly into it
cdkMoose