I am using the code below to open and read an xml file which is located on a remote computer. It does this fine, but once the code is executed, the XML file on the remote machine stays "open"--I cannot delete it, rename it, etc. because of a sharing violation.
I have executed "reader.Close" and "Stream.Close", but they do not close the file.
Any Ideas?
Dim Time As String
Try
' open the document...
Dim filestream As New System.IO.FileStream("\\" &_ machineName & "\" & "d$\Dat.xml", IO.FileMode.Open)
Dim reader As New XmlTextReader(filestream)
' move to the start of the document...
reader.MoveToContent()
' ignore whitespaces
reader.WhitespaceHandling = WhitespaceHandling.None
' start working through the document...
Do While reader.Read
' what kind of node is it?
Select Case reader.NodeType
' is it the start of an element?
Case XmlNodeType.Element
' if it's an element start, is it "logontime"?
If reader.Name = "logontime" Then
'If so, then read the value of the element
reader.ReadStartElement()
Time = reader.Value
End If
End Select
Loop
filestream.Close()
reader.Close()
Return Time
Catch ex As Exception
Time = ex.Message
End Try
End Function
I have executed "reader.Close" and "Stream.Close", but they do not close the file.
Any Ideas?
Dim Time As String
Try
' open the document...
Dim filestream As New System.IO.FileStream("\\" &_ machineName & "\" & "d$\Dat.xml", IO.FileMode.Open)
Dim reader As New XmlTextReader(filestream)
' move to the start of the document...
reader.MoveToContent()
' ignore whitespaces
reader.WhitespaceHandling = WhitespaceHandling.None
' start working through the document...
Do While reader.Read
' what kind of node is it?
Select Case reader.NodeType
' is it the start of an element?
Case XmlNodeType.Element
' if it's an element start, is it "logontime"?
If reader.Name = "logontime" Then
'If so, then read the value of the element
reader.ReadStartElement()
Time = reader.Value
End If
End Select
Loop
filestream.Close()
reader.Close()
Return Time
Catch ex As Exception
Time = ex.Message
End Try
End Function