XmlDocument::Save() appends the xml in file Try fs.SetLength(0); before Save call Add: fs.Position = 0; before the Save call.