I currently have a C# program that writes data to an XML file in using the .NET Framework.
if (textBox1.Text!="" && textBox2.Text != "")
{
XmlTextWriter Writer = new XmlTextWriter(textXMLFile.Text, null);
Writer.WriteStartDocument();
Writer.WriteStartElement("contact");
Writer.WriteStartElement("firstName");
Writer.WriteString(textBox1.Text);
Writer.WriteEndElement();
Writer.WriteEndElement();
Writer.WriteEndDocument();
Writer.Close();
}
else
{
MessageBox.Show("Nope, fill that textfield!");
}
The problem is that my XML file gets overwritten every time I try to save something new.
I've had both null
and Encoding.UTF8
for the second parameter in the XmlTextWriter
but it doesn't seem to be what changes the non-overwrite/overwrite function.