Folder ID
Folder Name
Folder Parent
for example root folder has an id of 0 and parent is -1 identifying it as the root folder
Subsequent folders relate back to thier parent id.
Here is the code I got:
'Format Code Block'
Public Sub getparentfolders(ByVal parentid As String, ByVal name As String, ByVal rootnode As RadTreeNode)
DBConn =
New SqlConnection(ConfigurationManager.ConnectionStrings("db").ToString)
Dim roottable As New DataTable
Dim rootrow As DataRow
roottable = FolderAPI.GetAllFoldersByParent(parentid, DBConn)
Dim subtable As New DataTable
For Each rootrow In roottable.Rows
Dim ParentNode As New RadTreeNode
ParentNode.Text = rootrow(1).ToString
ParentNode.Value = rootrow(0).ToString
'Do I have sub folders
subtable = FolderAPI.GetAllFoldersByParent(rootrow(0).ToString, DBConn)
If subtable.Rows.Count = 0 Then
rootnode.Nodes.Add(ParentNode)
Else
name = rootrow(1).ToString
getchildfolder(rootrow(0).ToString, name, ParentNode, rootnode, childnode)
End If
Next
FolderList.Nodes.Add(rootnode)
End Sub
Public Sub getchildfolder(ByVal parentid As String, ByVal name As String, ByVal ParentNode As RadTreeNode, ByVal rootnode As RadTreeNode, ByVal Childnode As RadTreeNode)
If Childnode.Text = "" Then Childnode = ParentNode
DBConn =
New SqlConnection(ConfigurationManager.ConnectionStrings("db").ToString)
Dim roottable As New DataTable
Dim rootrow As DataRow
roottable = FolderAPI.GetAllFoldersByParent(parentid, DBConn)
If roottable.Rows.Count < 1 Then
Try
rootnode.Nodes.Add(ParentNode)
Catch ex As Exception
Dim parentnode2 As New RadTreeNode
parentnode2.Text = name
parentnode2.Value = parentid
Dim rootnode2 As New RadTreeNode
rootnode2.Text =
"Home"
rootnode2.Value = 0
rootnode = rootnode2
rootnode.Nodes.Add(parentnode2)
End Try
End If
Dim newchild As New RadTreeNode
For Each rootrow In roottable.Rows
'Do I have more folders
name = rootrow(1).ToString
newchild.Text = name
newchild.Value = parentid
Childnode.Nodes.Add(newchild)
'getparentfolders(parentid, name, ParentNode)
getchildfolder(rootrow(0).ToString, name, ParentNode, rootnode, newchild)
Next
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim rootnode As New RadTreeNode
rootnode.Value = -1
rootnode.Text =
"Root"
getparentfolders(
"0", "Root", rootnode)
Here is where it gets annoying, Works fine except for folders with two sub folders.
Then I get this:
Specified argument was out of the range of valid values.
Parameter name: index
Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: index
Source Error:
|
In debugging you can see the parent folder all of a sudden has an index of 2. WTF?