I am importing information from XML files into a SQL Database. The import is working fine but some of the XML files have errors in them so therefore the code fails. I catch the exception and try to move the file to an error folder but as I was previously reading from the file I get an error saying the file is in use by another process. I have searched but havent came across any way of curing this yet. I have tried saving the document but still is in use when I try to move, Below is a sample of the code where I try to move the file for reference. Any suggestions on how to cure this would be great and thanks in advance for the information.
XmlDocument doc = new XmlDocument();
try
{
doc.Load(st);
}
catch(Exception ex)
{
doc.Save(st);
if (File.Exists(st))
File.Move(st, st + "\\Error");
}