tags:

views:

31

answers:

1

hi,

i am getting exception 'file in use by another process' for a xml file when checking system.io.file.exist() & then load it.I am using thread.monitor with this code.

Earlier when i was directly loading the xml file & not checking its local existence then i ws not getting thsi exception.

Can you please let me know, what's the cause for this 'file in use by another process' exception even when thread.monitor is applied !!

thanks in advance

gbhatnagar

A: 

here is my code,

Dim doc As XmlDocument = Nothing
Try
doc = New XmlDocument
If (System.IO.File.Exists(logFile)) Then
doc.Load(logFile)
Else
Dim objPI As Object = Nothing
Dim objPII As Object = Nothing
objPI = doc.CreateProcessingInstruction("xml", "version='1.0'")
objPII = doc.CreateProcessingInstruction("xml-stylesheet", "type='text/xsl' href='" & _sXLSTPath & "'")
doc.AppendChild(doc.CreateElement("Errors"))
doc.InsertBefore(objPII, doc.ChildNodes(0))
doc.InsertBefore(objPI, doc.ChildNodes(0))
End If
Catch exExceptionHandler As Exception
'write the exception in a text file
Return
End Try //proceed with code to add elements in xml & write