tags:

views:

65

answers:

2

how could i implement autosave in C#? i felt that saving to the currently open file is a simple but i may not want to overwrite my previous file (or should i just do that? i think google docs saves/overwrite the document tho they have version control?). i thought of saving to another file, but where do i save to?

also i guess i will have to know if there's any autosave files to retrieve and after a explicit save, i should remove the autosave file associated with the current document

+4  A: 

Current versions of Microsoft Office (for example) save to a "shadow copy" of the working file. Depending on how you want it to work, you can have writes applied to the shadow copy every n seconds or when certain types of actions are taken.

When the program is shut down, the original is deleted and the shadow copy is renamed to the original. There are lots of options and strategies within this technique that can be applied depending on your particular situation and requirements.

Dave Swersky
are you saying when the prog shuts down, the shadow copy replaces the original? and where is a good place to save these temporary files?
jiewmeng
Office saves the shadow copy in the same folder as the original, with a ~ at the beginning of the file name.
Dave Swersky
+1  A: 

You should create a Temporary File for the autosave. If the User saves, you can delete the file, and if your app crashes and is restarted it can load the last autosaved state from the file.

Tokk