I want to keep a single XmlDocument object in a class and let methods make changes to it and save it.
using (FileStream fs = new FileStream(@"D:\Diary.xml",
FileMode.Open, FileAccess.ReadWrite, FileShare.Read))
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(fs);
// ... make some changes here
xmlDoc.Save(fs);
}
The above code makes two copies of the xml structure inside the file.
Try
fs.SetLength(0);
before Save call
Add:
fs.Position = 0;
before the Save call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With