How to add Folders and SubFolders in TreeView

The following code helps you to get folders and subfolders in a treeview
Imports System.IO
 Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
        Dim FBD As New FolderBrowserDialog
        txtSelectedPath.Text = FBD.SelectedPath.ToString
        tvFoldernFiles.Nodes.Add(txtSelectedPath.Text.ToString, txtSelectedPath.Text)
        GetFilesnFolders(txtSelectedPath.Text.ToString, tvFoldernFiles.Nodes(txtSelectedPath.Text))
        Dim a As String() = tvFoldernFiles.TopNode.Text.Split("".ToCharArray)
        tvFoldernFiles.TopNode.Text = a(a.Length – 1).ToString.ToUpper
    End Sub
    Public Sub GetFilesnFolders(ByVal FolderName As String, ByVal RefNode As TreeNode)
        Dim FolderList As Array = Directory.GetDirectories(FolderName.ToString)
        Dim FileListofRoot As Array = Directory.GetFiles(FolderName.ToString)
        For int As Integer = 0 To FileListofRoot.Length – 1
            Dim RootFile As New TreeNode(FileListofRoot(int).ToString)
        For i As Integer = 0 To FolderList.Length – 1
            Dim TempNode As New TreeNode(FolderList(i).ToString.ToUpper)
            Dim FileList As Array = Directory.GetFiles(FolderList(i).ToString)
            GetFilesnFolders(FolderList(i), TempNode)
    End Sub

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: