This is a snippet of my asp code to display the files and folders of //SERVER/Documents directory in a collapsible treeview.
It works but I would want to make it more functional.
How it works, as everyone would have guessed, is that when the folder name (i.e f.name is the parent folder) it expands to display its content (files and folders).
Beside the folder name is an image (close.gif) to denote that this is a folder that needs to be clicked to expand and it just that, denotes. I would want the image to do the same as the folder name when clicked, expand or collapse the folder.
and at the same token, change the image to open.gif when expanded and change back to close.gif when collapsed.
Also, beside the file name is an image (bullet.gif). I would want it to open the file when clicked, the same way as when the file name (i.e fl1.name) is clicked.
The code below is from one of the thread in this forum and I just customized it to my specs.
in this piece of code: <a onClick="expandit(this)" onmouseover="style.cursor = 'hand'" class='sme' id="level">, do I need the class and id? and does it have to vary from span to span?
I would appreciate all the help.
<html>
<script language="JavaScript1.2">
<!--
var ns6=document.getElementById&&!document.all?1:0
var head="display:''"
var folder=''
function expandit(curobj){
folder=ns6?curobj.nextSibling.nextSibling.style:document.all[curobj.sourceIndex+1].style
if (folder.display=="none")
folder.display=""
else
folder.display="none"
}
//-->
</script>
<body>
<%
Dim fso, f, f1, fc, s,filedir
filedir = "//SERVER/Documents"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(filedir)
Set fc = f.SubFolders
%>
<b><font face=verdana size=2 color=blue><img src="close.gif"><a onClick="expandit(this)" onmouseover="style.cursor = 'hand'" class='sme' id="level"><%=f.name%></font></b></a>
<span style="display:none;color:blue;font-size:8pt;font-family:verdana;" style=&{head};>
<%
set fl = f.Files
For each fl1 in fl
%>
<br>
<img src="bullet.gif"><a href="<%=fl1.path%>" target="_blank" style="color:darkgreen;"><%=fl1.name%></a>
<%
' for level files
next
For Each sf1 in fc
%><br>
<img src="close.gif"><a onClick="expandit(this)" onmouseover="style.cursor = 'hand'" class='sme1' id="level1"><%=sf1.name%></a>
<span style="display:none;color:blue;" style=&{head};>
<%
set f1 = fso.GetFolder(sf1.path)
set sf2 = f1.SubFolders
set fl2 = f1.Files
For each fl3 in fl2
%>
<br>
<img src="bullet.gif"><a href="<%=fl3.path%>" target="_blank" style="color:darkgreen;"><%=fl3.name%></a>
<%
' for level 1 files
next
For each sf3 in sf2
%>
<br>
<img src="close.gif"> <a onClick="expandit(this)" onmouseover="style.cursor = 'hand'" class='sme1' id="level2"><%=sf3.name%></a>
<span style="display:none;color:bluen;" style=&{head};>
<%
set f2 = fso.GetFolder(sf3.path)
set sf4 = f2.SubFolders
set fl4 = f2.Files
For each fl5 in fl4
%>
<br>
<img src="bullet.gif"><a href="<%=fl5.path%>" target="_blank" style="color:darkgreen;"><%=fl5.name%></a>
<%
' for level 2 files
next
For each sf5 in sf4
%>
<br>
<img src="close.gif"><a onClick="expandit(this)" onmouseover="style.cursor = 'hand'" class='sme1' id="level3"><%=sf5.name%></a>
<span style="display:none" style=&{head};>
<%
set f3 = fso.GetFolder(sf5.path)
set sf6 = f3.SubFolders
set fl6 = sf5.Files
For each fl7 in fl6
%>
<br>
<img src="bullet.gif"><a href="<%=fl7.path%>" target="_blank" style="color:darkgreen;"><%=fl7.name%></a>
<%
' for fl6 files - which are fl17
next
%>
</span>
<%
next
%>
</span>
<%
next
%>
</span>
It works but I would want to make it more functional.
How it works, as everyone would have guessed, is that when the folder name (i.e f.name is the parent folder) it expands to display its content (files and folders).
Beside the folder name is an image (close.gif) to denote that this is a folder that needs to be clicked to expand and it just that, denotes. I would want the image to do the same as the folder name when clicked, expand or collapse the folder.
and at the same token, change the image to open.gif when expanded and change back to close.gif when collapsed.
Also, beside the file name is an image (bullet.gif). I would want it to open the file when clicked, the same way as when the file name (i.e fl1.name) is clicked.
The code below is from one of the thread in this forum and I just customized it to my specs.
in this piece of code: <a onClick="expandit(this)" onmouseover="style.cursor = 'hand'" class='sme' id="level">, do I need the class and id? and does it have to vary from span to span?
I would appreciate all the help.
<html>
<script language="JavaScript1.2">
<!--
var ns6=document.getElementById&&!document.all?1:0
var head="display:''"
var folder=''
function expandit(curobj){
folder=ns6?curobj.nextSibling.nextSibling.style:document.all[curobj.sourceIndex+1].style
if (folder.display=="none")
folder.display=""
else
folder.display="none"
}
//-->
</script>
<body>
<%
Dim fso, f, f1, fc, s,filedir
filedir = "//SERVER/Documents"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(filedir)
Set fc = f.SubFolders
%>
<b><font face=verdana size=2 color=blue><img src="close.gif"><a onClick="expandit(this)" onmouseover="style.cursor = 'hand'" class='sme' id="level"><%=f.name%></font></b></a>
<span style="display:none;color:blue;font-size:8pt;font-family:verdana;" style=&{head};>
<%
set fl = f.Files
For each fl1 in fl
%>
<br>
<img src="bullet.gif"><a href="<%=fl1.path%>" target="_blank" style="color:darkgreen;"><%=fl1.name%></a>
<%
' for level files
next
For Each sf1 in fc
%><br>
<img src="close.gif"><a onClick="expandit(this)" onmouseover="style.cursor = 'hand'" class='sme1' id="level1"><%=sf1.name%></a>
<span style="display:none;color:blue;" style=&{head};>
<%
set f1 = fso.GetFolder(sf1.path)
set sf2 = f1.SubFolders
set fl2 = f1.Files
For each fl3 in fl2
%>
<br>
<img src="bullet.gif"><a href="<%=fl3.path%>" target="_blank" style="color:darkgreen;"><%=fl3.name%></a>
<%
' for level 1 files
next
For each sf3 in sf2
%>
<br>
<img src="close.gif"> <a onClick="expandit(this)" onmouseover="style.cursor = 'hand'" class='sme1' id="level2"><%=sf3.name%></a>
<span style="display:none;color:bluen;" style=&{head};>
<%
set f2 = fso.GetFolder(sf3.path)
set sf4 = f2.SubFolders
set fl4 = f2.Files
For each fl5 in fl4
%>
<br>
<img src="bullet.gif"><a href="<%=fl5.path%>" target="_blank" style="color:darkgreen;"><%=fl5.name%></a>
<%
' for level 2 files
next
For each sf5 in sf4
%>
<br>
<img src="close.gif"><a onClick="expandit(this)" onmouseover="style.cursor = 'hand'" class='sme1' id="level3"><%=sf5.name%></a>
<span style="display:none" style=&{head};>
<%
set f3 = fso.GetFolder(sf5.path)
set sf6 = f3.SubFolders
set fl6 = sf5.Files
For each fl7 in fl6
%>
<br>
<img src="bullet.gif"><a href="<%=fl7.path%>" target="_blank" style="color:darkgreen;"><%=fl7.name%></a>
<%
' for fl6 files - which are fl17
next
%>
</span>
<%
next
%>
</span>
<%
next
%>
</span>