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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Building a folder tree from a database

Status
Not open for further replies.

emozley

Technical User
Jan 14, 2003
769
GB
Hi,

Does anyone know of any good/simple examples of building a folder tree based on the contents of a table?

FolderID | ParentID | Name
--------------------------
1 0 My Documents
2 1 Personal
3 1 Work
4 3 Confidential
5 0 My Photos

Would produce:

My Documents
Personal
Work
Confidential
My Photos

Thanks very much indeed - I have spent ages looking but cannot find anything.

Ed
 
Do you want to create actual folders or a "virtual" structure?

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Hi Chris,

It's a virtual structure - i.e. my documents are lumped into the same folder. I add 1000 and then create a new folder. I give them a unique ID as their file name and I store their original filename in the database.

I don't want to create folders just a list with tick boxes next to them that a user can tick to do other stuff.

My intended output actually had tabs in so I would want to do it with <ul> or something with some kind of recursive loop. If it was 'real' folders I could do it with about 10 lines of code and the filesystem object!

Thanks

Ed
 
Hi Chris,

Sorry I've just re-read your message and wanted to clarify - when I said "building a folder tree" I meant displaying a tree in HTML with subfolders indented.

Thanks

Ed
 
Somewhere in my ASP vbscript function library I have something like that, originally coded for a project document library as I recall.

I shall go delving into the dusty recesses of my drive archives to locate it.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Thanks very much! Incidentally I had a go and got this far. It was an adaptation of a recursive search through physical folders. The fileSystem object had a subfolders property so I created a little function to do something similar.

I have commented bits that were either not working or I only included to help me debug...

Code:
StartFolder=Request.Form("StartFolder") & ""
If StartFolder<>"" Then
  Response.Write("Showing folder tree for FolderID " & StartFolder & "<br>")
  TBL.Open "select folderid, pathtoroot, foldername from folders " &_
           "where pathtoroot like '%;" & StartFolder & ";%' " &_
           "or folderid=" & StartFolder & " " &_
           "order by pathtoroot", DB
  If Not TBL.EOF Then
    FolderArray=TBL.GetRows()
  End If
  ListFolderContents(StartFolder)
End If

Sub ListFolderContents(folderID)
  For i=0 To UBOUND(FolderArray, 2)
    Response.Write("<ul><b>" & FolderArray(0, i) & " " & FolderArray(2, i) & "</b>") 
    Response.Write("<ul>" & vbCrLf)
	PathString=GetSubFolders(FolderArray(0, i))
	Response.Write(PathString)
	
	SubFolders=Split(PathString, ";")
    'NumberOfSubFolders=UBOUND(SubFolders)-1
    'For j=2 To NumberOfSubFolders
    '  Response.Write("Getting subfolder for FolderID " & SubFolders(j))
	'  ListFolderContents(SubFolders(j))
    'Next
	
	Response.Write("</ul></ul>")
  Next
End Sub

Function GetSubFolders(folderID)
  'Response.Write(folderID)
  PathString=";"
  For j=0 To UBOUND(FolderArray, 2)
    SplitString=Split(FolderArray(1, j), ";")
	If SplitString(1)<>"" Then
	  If int(SplitString(1))=folderID Then 
	    PathString=PathString & FolderArray(0, j) & ";"
	  End If
	End If
  Next
  GetSubFolders=PathString
  
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top