Dim NumberOfCharacters As Integer = 2
Private Sub ExportFile()
Dim fp As StreamWriter
Dim FilePath As String
Dim Stream As String
FilePath = Server.MapPath(".\FolderToBeSavedin\") & "anyfile.doc"
fp = File.CreateText(FilePath)
Stream = GetStreamForAllNode()
fp.WriteLine(Stream)
fp.Close()
fp.Dispose()
End Sub
Function GetStreamForAllNode()
Dim node As FlyTreeNode
Dim sb As New StringBuilder()
Dim Level As Integer = 0
For Each node In TV.Nodes
sb.AppendLine("".PadLeft(Level * NumberOfCharacters, "-") & node.Text)
If node.ChildNodes.Count > 0 Then
Level += 1
AppendChildNodes(sb, Level, node)
Level -= 1
End If
Next
GetStreamForAllNode = sb.ToString()
End Function
Sub AppendChildNodes(ByRef psb As StringBuilder, ByRef pLevel As Integer, ByRef pnode As FlyTreeNode)
Dim node As FlyTreeNode
For Each node In pnode.ChildNodes
psb.AppendLine("".PadLeft(pLevel * NumberOfCharacters, "-") & node.Text)
If node.ChildNodes.Count > 0 Then
pLevel += 1
AppendChildNodes(psb, pLevel, node)
pLevel -= 1
End If
Next
End Sub