Hello. I am trying to combine an accordion panel and a tree view to make a dynamic navigation panel for a web page. The biggest problem is that users can add folders at any time, so the menu needs to be stored in a session variable. I can't find any way
to point a tree view directly to a directory structure, so I'm looking at java and css. I can get the effects that I want if I can just get the directory structure into an unordered list format. I basically need to start at a given level, then check all subfolders.
Any subfolders that have subfolders of their own will be added to a string along with the correct list item html and then do it all over again. Where I'm hitting a wall is the recursive listings. I can code in a set number of levels, each with it's own variables,
but that's not the right way to do it. Can anyone point me to the best way to do this?
So, essentially this is what I have. I need to figure out how to make this recursive. I tried using a stack, but the levels come out wrong (all of hte folders in the top level first, then all of the folders i nthe second level of the first folder etc.).
Any thoughts?
Dim rf As String = "D:\common"
Dim FSO As Object = CreateObject("Scripting.FileSystemObject")
Dim cf0, sfs0, sf0, f0, cf1, sfs1, sf1, f1 As Object
'begin new level
cf0 = FSO.GetFolder(rf)
sfs0 = cf0.subfolders
For Each sf0 In sfs0
f0 = sf0.subfolders
If f0.count > 0 Then
Session("menu") += "<li><a href='default2.aspx?loc=" & Server.UrlEncode(sf0.name) & "' target='frame'>" & sf0.name & "(0)</a>"
'begin new level
cf1 = FSO.GetFolder(sf0)
sfs1 = cf1.subfolders
Session("menu") += "<ul>"
For Each sf1 In sfs1
f1 = sf1.subfolders
If f1.count > 0 Then
'repeat levels of code here
End If
Next
Session("menu") += "</ul></li> "
End If
Next
For lack of a better way, I just hard coded multiple levels like so...
Dim CurrentFolder As Object = FSO.GetFolder(FullPath)
Dim L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11 As Object
Dim Path As String
Dim menu As String
L1 = CurrentFolder.subfolders
'next level
For Each a In L1
L2 = a.subfolders
Path = Server.UrlEncode(a.name)
If L2.count > 0 Then
'next level
For Each b In L2
L3 = b.subfolders
Path = Server.UrlEncode(a.name & "\" & b.name)
If L3.count > 0 Then
'next level
Marked as answer by spokey on Feb 16, 2011 02:18 PM
spokey
Member
111 Points
79 Posts
dynamically create an unordered list from directory the structure
Jun 14, 2010 06:28 PM|LINK
Hello. I am trying to combine an accordion panel and a tree view to make a dynamic navigation panel for a web page. The biggest problem is that users can add folders at any time, so the menu needs to be stored in a session variable. I can't find any way to point a tree view directly to a directory structure, so I'm looking at java and css. I can get the effects that I want if I can just get the directory structure into an unordered list format. I basically need to start at a given level, then check all subfolders. Any subfolders that have subfolders of their own will be added to a string along with the correct list item html and then do it all over again. Where I'm hitting a wall is the recursive listings. I can code in a set number of levels, each with it's own variables, but that's not the right way to do it. Can anyone point me to the best way to do this?
spokey
Member
111 Points
79 Posts
Re: dynamically create an unordered list from directory the structure
Jun 17, 2010 02:09 PM|LINK
So, essentially this is what I have. I need to figure out how to make this recursive. I tried using a stack, but the levels come out wrong (all of hte folders in the top level first, then all of the folders i nthe second level of the first folder etc.). Any thoughts?
Dim rf As String = "D:\common" Dim FSO As Object = CreateObject("Scripting.FileSystemObject") Dim cf0, sfs0, sf0, f0, cf1, sfs1, sf1, f1 As Object 'begin new level cf0 = FSO.GetFolder(rf) sfs0 = cf0.subfolders For Each sf0 In sfs0 f0 = sf0.subfolders If f0.count > 0 Then Session("menu") += "<li><a href='default2.aspx?loc=" & Server.UrlEncode(sf0.name) & "' target='frame'>" & sf0.name & "(0)</a>" 'begin new level cf1 = FSO.GetFolder(sf0) sfs1 = cf1.subfolders Session("menu") += "<ul>" For Each sf1 In sfs1 f1 = sf1.subfolders If f1.count > 0 Then 'repeat levels of code here End If Next Session("menu") += "</ul></li> " End If Nextspokey
Member
111 Points
79 Posts
Re: dynamically create an unordered list from directory the structure
Feb 16, 2011 02:18 PM|LINK
For lack of a better way, I just hard coded multiple levels like so...
Dim CurrentFolder As Object = FSO.GetFolder(FullPath) Dim L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11 As Object Dim Path As String Dim menu As String L1 = CurrentFolder.subfolders 'next level For Each a In L1 L2 = a.subfolders Path = Server.UrlEncode(a.name) If L2.count > 0 Then 'next level For Each b In L2 L3 = b.subfolders Path = Server.UrlEncode(a.name & "\" & b.name) If L3.count > 0 Then 'next level