This is a migrated thread and some comments may be shown as answers.

TreeView Directory Structure location

0 Answers 74 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
CliffE
Top achievements
Rank 1
CliffE asked on 10 Jun 2010, 08:55 PM
Imports System  
Imports System.IO  
 
Imports Telerik.Web.UI  
 
Namespace Telerik.Web.Examples.TreeView.DirectoryStructure  
 
    Partial Public Class DefaultVB  
        Inherits System.Web.UI.Page  
 
        Private ReadOnly KnownExtensions As String() = New String() {"aspx", "asmx", "cs", "vb", "xml", "ascx", _  
         "jpg", "png", "gif", "html", "pdf"}  
 
        Private Sub BindTreeToDirectory(ByVal virtualPath As String, ByVal parentNode As RadTreeNode)  
            Dim physicalPath As String = Server.MapPath(virtualPath)  
            Dim directories As String() = Directory.GetDirectories(physicalPath)  
            For Each directory As String In directories  
                Dim node As New RadTreeNode(Path.GetFileName(directory))  
                node.Value = virtualPath + "/" + Path.GetFileName(directory)  
                node.ImageUrl = "~/TreeView/Img/Vista/folder.png" 
                node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack  
                parentNode.Nodes.Add(node)  
            Next  
 
            Dim files As String() = Directory.GetFiles(physicalPath)  
            For Each file As String In files  
                Dim node As New RadTreeNode(Path.GetFileName(file))  
                Dim extension As String = Path.GetExtension(file).ToLower().TrimStart("."c)  
 
                If Array.IndexOf(KnownExtensions, extension) > -1 Then  
                    node.ImageUrl = "~/TreeView/Img/Vista/" + extension + ".png"  
                Else  
                    node.ImageUrl = "~/TreeView/Img/Vista/unknown.png" 
                End If  
 
                parentNode.Nodes.Add(node)  
            Next  
        End Sub  
 
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load  
            If Not Page.IsPostBack Then  
                Dim rootNode As New RadTreeNode("8000")  
                rootNode.Value = "2009" 
                rootNode.ImageUrl = "~/TreeView/Img/Vista/folder.png" 
                rootNode.Expanded = True 
                rootNode.SelectedImageUrl = True 
                rootNode.ExpandMode = TreeNodeExpandMode.ServerSideCallBack  
                RadTreeView1.Nodes.Add(rootNode)  
            End If  
        End Sub  
 
        Protected Sub RadTreeView1_NodeExpand(ByVal sender As Object, ByVal e As RadTreeNodeEventArgs)  
            BindTreeToDirectory(e.Node.Value, e.Node)  
        End Sub  
 
    End Class  
 
End Namespace  
 
 
 
 


I am having issues pulling folders/files from a server share into RadTreeView.  Can someone look at my vb code and help?

No answers yet. Maybe you can help?

Tags
TreeView
Asked by
CliffE
Top achievements
Rank 1
Share this question
or