Here is the code that I am using. I am referencing the file in the last sub-routine "Save_Click".
Sub SaveNodes(ByVal nodesCollection As TreeNodeCollection, ByVal textWriter As System.Xml.XmlTextWriter)
Dim link_node As TreeNode
For Each link_node In nodesCollection
If link_node.ChildNodes.Count Then
textWriter.WriteStartElement("Folder")
textWriter.WriteAttributeString("Name", link_node.Text)
textWriter.WriteRaw(vbCrLf)
Else
textWriter.WriteStartElement("Link")
textWriter.WriteAttributeString("Name", link_node.Text)
textWriter.WriteAttributeString("Location", link_node.NavigateUrl)
End If
If link\_node.ChildNodes.Count > 0 Then
SaveNodes(link\_node.ChildNodes, textWriter)
End If
textWriter.WriteEndElement()
textWriter.WriteRaw(vbCrLf)
Next
End Sub
Sub SaveTreeViewData(ByVal treeView As TreeView, ByVal path As String)
'Create a serializer and file to save TreeViewData
Dim TextWriter As New System.Xml.XmlTextWriter(path, System.Text.Encoding.UTF8)
TextWriter.WriteStartDocument()
TextWriter.WriteRaw(vbCrLf)
SaveNodes(treeView.Nodes, TextWriter)
TextWriter.Close()
End Sub
Protected Sub Save_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Save.Click
SaveTreeViewData(Link_Tree, "favorites.xml")
End Sub