資料|資料庫|資料庫結構 Folder 表:
Folderid:目錄ID,自動編號
FolderParentID:上級目錄ID,Int
FolderName:目錄名稱,Varchar
FolderDescription:目錄說明,Varchar
File 表:
FileID:文檔ID,自動編號
FileFolderID:所屬目錄ID,Int
FileName:文檔名稱,Varchar
FileDescription:文檔內容,Varchar或備忘(ntext)
function GetAllChildID(id)
'取得FolderID為id的目錄下所有子目錄的FolderID,以半形逗號分開
dim arrID
arrID = id
Set rsdir = Conn.Execute("Select FolderID,FolderParentID from [Folder] where FolderParentID = " & id & "")
if rsdir.eof and rsdir.bof then
set rsdir = nothing
GetAllChildID = arrID
exit function
else
while not rsdir.eof
arrID = arrID & "," & GetAllChildID(rsdir("FolderID"))
rsdir.movenext
wend
end if
set rsdir = nothing
GetAllChildID = arrID
end function
'從表File中取得某個目錄下所有文檔的Sql
dim AllChildID
AllChildID = GetAllChildID(5) '取得FolderID為5下所有目錄的FolderID
AllfileSql = "Select FileID,FileName from [File] where FileFolderID in ("& AllChildID &")"
?
function FolderPath(id)
'得到一個目錄的完整路徑
dim Pathstr,NewPathstr
Set rsdir = Conn.Execute("Select FolderID,FolderName,FolderParentID from [Folder] where FolderID = " & id)
if rsdir.bof and rsdir.eof then
Pathstr = ""
else
Pathstr = "<a href=""Folder.asp?FolderID=" & rsdir("FolderID") &""">" & rsdir("FolderName") & "</a> > " & Pathstr
if rsdir("FolderParentID") <> 0 then
Pathstr = FolderPath(rsdir("FolderParentID")) & Pathstr
end if
end if
NewPathstr = Pathstr
set rsdir = nothing
FolderPath = NewPathstr
end function
dim folderpathstr
folderpathstr = FolderPath(67)
response.write folderpathstr '輸出 (技術文檔 > Web開發 > ASP > Code Sample > 表單 > )