I have a WPF app which saves a few textboxes in a XML file.
But for some reason sometimes it saves ok and the other time it does not.
And the problem always is how it closes the XML file.
For example, closing the XML file shoudl end with
</Data>
But usualy when it goes wrong it has something like
</Data>Data> or even more.
Am i forced to clear my XML file each time before writing new data to it?
Code currently used for writing to it is.
private void WriteXml(string filename)
{
tx.Name = txtName.Text;
tx.HotKey = txtHotKey.Text;
tx.Timer = txtDuration.Text;
tx.Message = txtReminderMsg.Text;
XmlSerializer writer = new XmlSerializer(typeof(Data));
using (FileStream file = File.OpenWrite(filename))
{
writer.Serialize(file, tx);
}
}
Honeslty i have never used XML before in a project.
But by the looks of it its almost as if when one of the textboxes has less characters then before.
It will be saved wrong.
I assumed a XML file is saved line per line, not 1 big line with x amount of characters.