Re: Preserve State



In a simple desktop application, when the user starts my program again, I want her to find things just as she left them last time. What is a simple straightforward way to implement such persistence?


Look at the MSDN documentation for the System.Configuration.ApplicationSettingsBase class and the See Also Reference links. There are alot of links that describe how.

Also
http://msdn2.microsoft.com/en-us/library/0zszyc6e.aspx

When I go through the steps described in the link above and implement an ApplicationSettingsBase-object for my Form, the system writes out a file 'user.config' somewhere deep in C:\Documents and Settings\UserName\Local Settings\Application Data\... This file contains xml. When I (deliberatly) corrupt this file I can no longer read from it or write to it. The exception it raises can by caught with two try{}catch{} blocks, one for reading it and one for writing to it. But than the whole mechanism is vanished. I cannot read from the corrupt file, I cannot write to the corrupt file and I cannot (untill now) replace it with a new and valid user.config file.

Is there a safe way to start with a clean ***, once the user.config file is corrupted?

.