Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

export to text file

Status
Not open for further replies.

231166

Programmer
Apr 5, 2005
104
0
0
FR
Hi,

I have created a treeview called TreeView1.
In this treeview you can find several terms which are considered as Roots because they are at the first level of the treeview.

I have created a sub to import into a textfile the entire treeview.

Here is the code of this sub.

Code:
Private Sub ExportTreeViewToTxt(ByVal TreeView As TreeView, ByVal OutputPath As String)
        Dim clsPrompt As SaveFileDialog
      
        If Not IsNothing(OutputPath) Then
            'open stream... 
            [green] 'use recursive function to write out file... [/green]
            Dim clsOutStream As New System.IO.MemoryStream
            Dim clsWriter As New System.IO.StreamWriter(clsOutStream)
            ExportToText(TreeView1.Nodes, 0, clsOutStream)
          [green]  'close stream... [/green]
            clsOutStream.Flush()
            clsOutStream.Close()
            clsPrompt = New SaveFileDialog
            clsPrompt.Title = "Select Output File"
            clsPrompt.Filter = "Text Files {*.txt}|*.txt"
            If clsPrompt.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then
                OutputPath = clsPrompt.FileName
            End If
            clsOutStream.Close()
        End If

    End Sub
Code:
Private Sub ExportToText(ByVal Nodes As TreeNodeCollection, ByVal Indentation As Integer, ByVal OutStream As System.IO.MemoryStream)
        Dim clsOutStream As System.IO.MemoryStream
        For Each clsNode As TreeNode In Nodes
       [green]     'write out node at the specified indentation... [/green]
            Dim clsWriter As New System.IO.StreamWriter(clsOutStream)
            clsWriter.WriteLine(New String(" "c, Indentation * 4) & " - " & clsNode.Text)
          [green]  'write out child nodes... [/green]
            Call ExportToText(clsNode.Nodes, Indentation + 1, clsOutStream)
          [green]  ' flush stream.. [/green]
            clsWriter.Flush()
            clsOutStream.Position = 0
            Dim clsReader As New System.IO.StreamReader(clsOutStream)
            MessageBox.Show(clsReader.ReadToEnd())
        Next
    End Sub
Now, if the user clicks on one root term and clicks after on the menuitem 'export to txt'i would like him to export to a txtfile [blue]ONLY THE ROOT and all its specific terms( all the terms which are below it in the treeview)[/blue]

Could you help me to code this ; perhaps i need to make changes to the existing code.

Thanks alot for all your precious help.

Best regards.

Nathalie
 
Check out the SelectedNode.FullPath in help.

I hope that this helps.

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
Hi,

Can you explain to me what means [blue]Check out the SelectedNode.FullPath in help.{[/blue]

You mean i need to write a path instead of TreeView1.Nodes here in the code
[green]ExportToText(TreeView1.Nodes, 0, clsOutStream)[/green]

How can i write a fullpath?

Thanks a lot for your help.

Best Regards.

Nathalie


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top