I am upgrading a vb 6.0 app to .net and I'm having trouble moving a file. The app retrieves info from an XML. When it's done I try to move the .xml file to a history folder and I'm getting an error:
An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll
Additional information: The process cannot access the file because it is being used by another process.
How do I release the file?
Here's my code

Dim root As MSXML2.IXMLDOMElement
    Dim objXMLdoc As New MSXML2.DOMDocument30()
            objXMLdoc.Load(Filename)
            objXMLdoc.async = False
            root = objXMLdoc.documentElement.firstChild.firstChild
            GetXMLData() 'USES XPATH... TO RETRIEVE DATA
            OutPutRecord() 'outputs retrieved data to an SQL Database
            MoveFile(Filename)
    Public Function MoveFile(ByVal strfile As String) As Boolean
        Dim objfile As New FileInfo(strfile)
        'Try
        objfile.MoveTo(Filename)
        'Return True
        'Catch
        '   Return False
        '  End Try
    End Function

Recommended Answers

All 2 Replies

You are still referencing the file thru the objXMLdoc. Try this

objXMLdoc.Load(Filename)
            objXMLdoc.async = False
            root = objXMLdoc.documentElement.firstChild.firstChild
            GetXMLData() 'USES XPATH... TO RETRIEVE DATA
            OutPutRecord() 'outputs retrieved data to an SQL Database
            objXMLdoc = Nothing
            MoveFile(Filename)

It turns out I did not show enough of my code in the first post. The process was actually croaking in another section altogether. There is another spot that I create an XML using FSO. I converted it to StreamWriter and I'm up and rolling! Well I'm ready to tackle the next challenge in the app!

Thanks Wayne

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.