Hi,
I use this class to save application settings in a xml file. Sometime I have
exception error in the Load method, and sometime in the Save method. Is this
a bug in NET or is there something I do wrong ? I load in the form Load and
save in the FormClosing. This is the class:
public class Config
{
public formSettings MainForm = new formSettings();
public appVersion AppVersion = new appVersion();
public Server server = new Server();
public Config Load(string FileName)
{
try {
XmlSerializer serializer = new XmlSerializer(typeof(Config));
FileStream stream = new FileStream(FileName, FileMode.Open);
try {
return (Config)serializer.Deserialize(stream);
} finally {
stream.Close();
}
} catch {
return new Config();
}
}
public void Save(string FileName)
{
XmlSerializer serializer = new XmlSerializer(typeof(Config));
TextWriter writer = new StreamWriter(FileName);
serializer.Serialize(writer, this);
writer.Close();
}
public class formSettings
{
public Point Location;
public Size Size;
}
public class Server
{
public string server = "localhost";
public string port = "2804";
public bool activate = false;
}
public class appVersion
{
public string version;
}
}
--
rgds, Wilfried
http://www.mestdagh.biz