Re: Preserve State
- From: "Doug Semler" <dougsemler@xxxxxxxxx>
- Date: Sun, 30 Sep 2007 16:13:53 -0400
"Martijn Mulder" <i@m> wrote in message news:46ffffc9$0$94823$dbd4f001@xxxxxxxxxxxxxxxxxx
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?
Well, there's a reason that the file is buried where it is. The file is maintained by the framework...there's really no reason for you to be mucking with it...and in fact can be located in a differnt location based on whether it's click-once, roaming profile, even version number of the app. Let the framework handle this file and you should be fine...
There is a Reset() function on applicationSettingsBase that you could try calling but I think that still tries to call a Reload(), which will cause an exception if the file is corrupt.
ANY data file that has corrupted data will cause unexpected results, whether it's an XML file that the framework is maintaining or some binary file that you are writing.
--
Doug Semler, MCPD
a.a. #705, BAAWA. EAC Guardian of the Horn of the IPU (pbuhh).
The answer is 42; DNRC o-
Gur Hfrarg unf orpbzr fb shyy bs penc gurfr qnlf, abbar rira
erpbtavmrf fvzcyr guvatf yvxr ebg13 nalzber. Fnq, vfa'g vg?
.
- References:
- Preserve State
- From: Martijn Mulder
- Re: Preserve State
- From: Doug Semler
- Re: Preserve State
- From: Martijn Mulder
- Preserve State
- Prev by Date: Re: How do i convert a byte[2] with format big endian signed int to a integer value?
- Next by Date: Re: Map a network share with WNetAddConnection3
- Previous by thread: Re: Preserve State
- Next by thread: Re: Focus Topmost form Only
- Index(es):