Found the solution. I use fs.SetLength(0) to set the stream to empty and then I save back the XML into it.
VB Code:
Public sub UpdateControl() Dim Doc As New XmlDocument Dim fs As FileStream Try fs = New FileStream(_BatchListFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None) ' Load the XML through the filestream Doc.Load(fs) ' Pick up node using SelectSingleNode and update fs.SetLength(0) ' This clears any previous data from the file ' Write back the Xml file Doc.Save(fs) Catch ex as Exception throw new Exception("", ex) Finally if not(fs is nothing) Then fs.close fs = nothing End If End Try End Sub




Reply With Quote