Hi Arjay

Thanks for responding. I will try the change you had recommended.

Here is how I create the XML file. For few reasons, the user might process the same file again. So I first check for the existence of the file and if it exists, I try to delete the existing XML file:

if (File.Exists(strXmlPath + "\\" + strFileName + ".xml"))
File.Delete(strXmlPath + "\\" + strFileName + ".xml");

strXmlFilename = strXmlPath + "\\" + strFileName + ".tmp";
Xmlwriter = new XmlTextWriter(strXmlFilename, Encoding.UTF8);
Xmlwriter.Formatting = Formatting.Indented;
Xmlwriter.Indentation = 5;
Xmlwriter.WriteStartDocument();

//Then all the nodes in the XML file

Xmlwriter.WriteEndDocument();
Xmlwriter.Flush();
Xmlwriter.Close();
//This is rename the .tmp file to xml file
if (File.Exists(strXmlFilename))
{
File.Move(strXmlFilename, strXmlPath + "\\" + strFileName + ".xml");
}

At times the program fails during the delete command. At times the program fails during Xmlwriter = new XmlTextWriter line.

Let me know if you would need further info on this.

Thanks