Xml file gets corrupted on abruptly system shutdown.

  • Thread starter Thread starter Anand Kumar Irusan
  • Start date Start date
A

Anand Kumar Irusan

Guest
We have a xml file, which gets created before start performing certain application logic. In a normal circumstance the xml file creation is created fine. The Xml file gets corrupted only if any hard shutdown takes place. While execution though the application creates the xml file successfully and the hard shutdown takes places only when the application executing the expected application logic, hence not sure why the xml file gets corrupted.


XmlDocument XD = null;
XmlNode Root = null;
XmlNode Child = null;
XmlAttribute ChildAtt = null;
try
{
XD = new XmlDocument();
Root = XD.AppendChild(XD.CreateElement("PersonalDetails"));
Child = Root.AppendChild(XD.CreateElement("Person"));
ChildAtt = Child.Attributes.Append(XD.CreateAttribute("Name"));
ChildAtt.InnerText = "Anand";
ChildAtt = Child.Attributes.Append(XD.CreateAttribute("Age"));
ChildAtt.InnerText = "28";
string filePath = @"D:\Tempfolder\newFile.xml";

if (File.Exists(filePath))
File.Delete(filePath);
using (XmlTextWriter writer = new XmlTextWriter(filePath, null))
{
writer.Formatting = Formatting.Indented;
XD.Save(writer);
writer.Close();
XD = null;
}
//Below function call will takes longer time peroid Ex:(5-10) minutes..
//The hard shutdown takes place while executing the below function call only.
callLogic();
}
catch (Exception ex)
{
throw ex;
}


Any advice appreciated.

Continue reading...
 
Back
Top