> > > You could serialize a simple class to the users' application directory
(see the Environment.Spe cialFolder enumeration). To re-load those
settings, just de-serialize the file.
Well, this helps part of my problem.
The second problem is this serialization, because I want Myprogram v1.0
still be able to read Myprogram v1.5 settings and vice versa.
A lot of sollutions I found are not worth it since it somehow converts
the v1.0 to v1.5 and no way to return back. So I am stil looking into this
to find a elegant sollution.
You could implement the ISerializable interface and control
serialization/deserialization yourself. During serialization, you could
write out a version number. Likewise, during deserialization , you could
read this version number and make sure your current application supports
that version.
For the moment I am using the xml direction (XmlDocument).
At first I thought this was something like ini files, just a little bit more
nestend then it turns out that it is far advanced, it is close to a
database.
I had some small problem with reloading the file an add things to it without
losing the other unknown information.
I wanted a program v1.0 to read a v2.0 xml configuration file, and save the
settings whie it stays a v2.0 xml file, thus the v2.0 program still have all
it's configuration available. Only when I see that some nodes are missing, I
add them.
It took me some time to realize that mXmlDocument.Se lectSingleNode( ) has
some SQL-like (actually XPath) syntax.
So mLastUsedNode=m XmlDocument.Sel ectSingleNode(" LastUsed"; always returned
null,
I had to use
mLastUsedNode=m XmlDocument.Sel ectSingleNode(" descendant::Las tUsed") instead.
(see code sampple)
--------------------------
mLastUsedNode=m XmlDocument.Sel ectSingleNode(" descendant::Las tUsed");
if (mLastUsedNode= =null ) {
mLastUsedNode=m Configuration.A ppendChild(mXml Document.Create Element("LastUs e
d"));
}
----------------------
One other thing that I now realize is to filter the characters that you re
going to save. Filling in a string "<blabla" might crash the xml.
The same typical problems SQL databases have.
The xml direction is a good direction what I want to do.
Only the stability scares me a little, it is as unstable as other database
engines.
e.g. I open the xml file with notepad, an it crashes my explorer.
Other example is something like this:
mDoctype = mXmlDocument.Cr eateDocumentTyp e("this has spaces in between",
null, null, null);
It also crashes my explorer. :-(
But this fixes it
mDoctype = mXmlDocument.Cr eateDocumentTyp e("this_has_spa ces_in_between" ,
null, null, null);
I do like the XML file format!
I only hope that Micrsoft does something to make it more stabel.