INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Building a folder tree from a database

Building a folder tree from a database

(OP)
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

RE: Building a folder tree from a database

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

RE: Building a folder tree from a database

(OP)
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

RE: Building a folder tree from a database

(OP)
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

RE: Building a folder tree from a database

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

RE: Building a folder tree from a database

(OP)
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 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close