Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP folder treeview - links to items

Posted on 2009-07-07
3
Medium Priority
?
352 Views
Last Modified: 2012-05-07
Hi,

I am trying to create a treeview of the folders, their subfolders, and files in a specific network share. I have accomplished this so far by getting some open source code off the net. The tree is loading fine; though, I WOULD LIKE THE FILES SHOWN TO HAVE DIRECT LINKS TO THEM. This means that you would be able to click on it in the tree. Can someone please help? (look at the attached code)
<%
Option Explicit
 
Class Collection
	Private m_next,m_len
	Private m_dic	
	
	Public Sub Add(Item)
		m_dic.Add "K" & m_next,Item
		m_next = m_next+1		
		m_len = m_len+1		
	End Sub
	
	Public Sub Clear
		m_dic.RemoveAll 
	End Sub
	
	Public Function Length
		Length=m_len
	End Function
	
	Public Default Function Item(Index)
		Dim tempItem,i
		For Each tempItem In m_dic.Items 
			If i=Index Then
				Set Item=tempItem
				Exit Function
			End If
			i=i+1
		Next	
	End Function
	
	Public Sub Remove(ByVal Index)
		Dim Item,i
		For Each Item In m_dic.Items 
			If i=Index Then
				m_dic.Remove(Item)
				m_len=m_len-1
				Exit Sub
			End If
			i=i+1
		Next			
	End Sub
	
	Private Sub Class_Initialize
		m_len=0
		Set m_dic = Server.CreateObject("Scripting.Dictionary")				
	End Sub
	
	Private Sub Class_Terminate
		Set m_dic = Nothing				
	End Sub
End Class
 
Class Node	
	'Public Parent
	Public Text
	Public Href
	Public Target
	Public ToolTipText
	Public ChildNodes
	Public ImageUrl
	Public ID
	
	Public Sub Init(strText,strHref,strToolTipText)
		Text=strText
		Href=strHref
		ToolTipText=strToolTipText
	End Sub
	Public Sub Add(objNode)
		ChildNodes.Add(objNode)
	End Sub
	
	Private Sub Class_Initialize
		Set ChildNodes = New Collection				
	End Sub
	
	Private Sub Class_Terminate
		Set ChildNodes = Nothing				
	End Sub
End Class
 
Class TreeView
	
	Private m_folder
	Public Color	
	Public Nodes
	Public DefaultTarget
	Public ID
	
	Public Property Let ImagesFolder(strFolder)
		m_folder=strFolder
	End Property
	Public Property Get ImagesFolder()
		ImagesFolder=m_folder	
	End Property
	
	Private Sub Class_Initialize
		Set Nodes = New Collection	
		Color="Navy"
		m_folder="images"					
	End Sub
	
	Private Sub Class_Terminate
		Set Nodes = Nothing				
	End Sub
	
	Public Function AddNode(Text)
		Dim tn 
		Set tn = new Node
		tn.Text=Text
		Nodes.Add(tn)
	End Function
	
	Public Function CreateNode(Text,Href,ToolTipText)
		Dim tn 
		Set tn = new Node
		Call tn.Init(Text,Href,ToolTipText)
		Set CreateNode=tn
	End Function
	Public Function CreateSimpleNode(Text)
		Dim tn 
		Set tn = new Node
		tn.Text = Text
		Set CreateSimpleNode=tn
	End Function
 
	
	Private Sub LoopThru(NodeList,Parent)	
		Dim i,j,Node,blnHasChild,strStyle
		
		If Parent<>"0" Then
			Out ("<ul class=tree id=""N" & Parent & """>")
		Else
			Out ("<ul xstyle='margin-left:20px;' id=""N" & Parent & """>")
		End If
		For i=0 To NodeList.Length-1
			Set Node = NodeList(i)		
			If (Node.ChildNodes.Length>0) Then 
				blnHasChild=True	
			Else
				blnHasChild=False
			End If
			If Node.ImageUrl="" Then
				strStyle=""
			Else
				strStyle="style='list-style-image: url("& Node.ImageUrl &");'"
			End If				
			If blnHasChild Then
				Out("<li "& strStyle &" class=folder id=""P" & Parent & i & """><a class=treeview href=""javascript:toggle"& id &"('N" & Parent & "_" & i & "','P" & Parent & i & "')"">" & Node.Text & "</a>")
			Else
				If Node.Target="" Then
					Node.Target=DefaultTarget
				End If
				Out("<li "& strStyle &" class=file><a class=treeview href=""" & Node.Href & """ target=""" & Node.Target & """  title=""" & Node.ToolTipText & """>" & Node.Text & "</a>")
			End If
			
			If blnHasChild Then		
				Call LoopThru(Node.ChildNodes,Parent & "_" & i)
			End If	
					
			Out ("</li>")
		Next
		Out ("</ul>")
	End Sub
 
	Private Sub Out(s)
		Response.Write(s)
	End Sub
	
	Public Sub Display
		Out("<script>function toggle"& id &"(id,p){var myChild = document.getElementById(id);if(myChild.style.display!='block'){myChild.style.display='block';document.getElementById(p).className='folderOpen';}else{myChild.style.display='none';document.getElementById(p).className='folder';}}</script>")
		Out("<style>ul.tree{display:none;margin-left:17px;}li.folder{list-style-image: url("& ImagesFolder &"/plus.gif);}li.folderOpen{list-style-image: url("& ImagesFolder &"/minus.gif);}li.file{list-style-image: url("& ImagesFolder &"/dot.gif);}a.treeview{color:"& Color &";font-family:verdana;font-size:8pt;}a.treeview:link {text-decoration:none;}a.treeview:visited{text-decoration:none;}a.treeview:hover {text-decoration:underline;}</style>")
		Call LoopThru(Nodes,0)		
	End Sub
	
	Public Sub LoadFromDB(strConn,strMenuTable)
		Dim Conn 
		Set Conn = Server.CreateObject("ADODB.Connection")
		Conn.Open strConn
		
		Dim RS,node,parentid,parentNode
		Set RS = Conn.Execute("SELECT * FROM " & strMenuTable & " ORDER BY MenuID,ParentID")
		
		If Not RS.EOF Then
			Do While Not RS.EOF
				parentid=RS("ParentID")
				
				Dim child				 
				Set child = new Node
				Call child.Init(RS("Text"),RS("URL"),RS("ToolTip"))
				child.ID =RS("MenuID")
				
				If parentid=0 then
					Nodes.Add(child)
				Else
					Set parentNode = FindNode(Nodes,ParentID)
					If Not (parentNode is Nothing) Then
						parentNode.Add(child)
					End If
				End If
				RS.MoveNext		
			Loop
			RS.Close
		End If
		Set RS = Nothing
		Conn.Close 
		Set Conn = Nothing		
	End Sub
	
	Private Function FindNode (nodes,ID)
		dim i,tempNode		
		For i=0 To nodes.Length-1
			Set tempNode = nodes(i)
			if tempNode.Id=ID then
				Set FindNode=tempNode
				Exit Function
			Else
				If tempNode.ChildNodes.length>0 Then
					Set tempNode = FindNode(tempNode.ChildNodes,ID)
					If Not (tempNode is Nothing) Then
						Set FindNode=tempNode
						Exit Function
					End If
				end if
			End If				
		Next
		Set FindNode = Nothing			
	End Function
	
	Public Sub DisplayFolderContents(ByVal strFolderPath)
		Out("<script>function toggle"& id &"(id,p){var myChild = document.getElementById(id);if(myChild.style.display!='block'){myChild.style.display='block';document.getElementById(p).className='folderOpen';}else{myChild.style.display='none';document.getElementById(p).className='folder';}}</script>")
		Out("<style>ul.tree{display:none;margin-left:17px;}li.folder{list-style-image: url("& ImagesFolder &"/plus.gif);}li.folderOpen{list-style-image: url("& ImagesFolder &"/minus.gif);}li.file{list-style-image: url("& ImagesFolder &"/dot.gif);}a.treeview{color:"& Color &";font-family:verdana;font-size:8pt;}a.treeview:link {text-decoration:none;}a.treeview:visited{text-decoration:none;}a.treeview:hover {text-decoration:underline;}</style>")
 
 
 
 
 
 
 
 
 
		Dim fso 
	  Set fso = Server.CreateObject("Scripting.FileSystemObject")
		If fso.FolderExists(strFolderPath) Then			
			Call ListFolderContents(fso.GetFolder(strFolderPath),0)			
		Else
			Out "<font color=red>Folder <b>'" & strFolder & "'</b> does not exist</font>"
		End If
	
		Set fso = Nothing
	End Sub
	
	Private Sub ListFolderContents(objFolder,Parent)
		Dim objSubFolder, objFile	
		If Parent<>"0" Then
			Out ("<ul class=tree id=""N" & Parent & """>")
		Else
			Out ("<ul xstyle='margin-left:20px;' id=""N" & Parent & """>")
		End If	
		
		dim i
		For Each objSubFolder In objFolder.SubFolders
			Out("<li class=folder id=""P" & Parent & i & """><a class=treeview href=""javascript:toggle"& id &"('N" & Parent & "_" & i & "','P" & Parent & i & "')"">")
			Out objSubFolder.Name & "</a>"			
			Call ListFolderContents(objSubFolder,Parent & "_" & i)
			Out "</li>"
			i=i+1
		Next
		
		For Each objFile In objFolder.Files
			Out "<li class=file>" & objFile.Name & "</li>"
		Next
		
		Out "</ul>"
		
		Set objFile = Nothing
		Set objSubFolder = Nothing
		
	End Sub
End Class
 
 
 
 
%>
 
<!--
 
	
	Public Sub LoadFromDB(strConn,strMenuTable)
		Dim Conn 
		Set Conn = Server.CreateObject("ADODB.Connection")
		Conn.Open strConn
		
		
		Call AddNodesFromDB(Conn,strMenuTable,0,-1)
		
		Conn.Close 
		Set Conn = Nothing		
	End Sub
	
	Private Sub AddNodesFromDB(objConn,strTable,intParentId,intDepth)
		Dim RS,node
		Set RS = objConn.Execute("SELECT * FROM " & strTable & " WHERE ParentID=" & intParentId)
		intDepth=intDepth+1
		If Not RS.EOF Then
			Do While Not RS.EOF
				node
				'Call AddNodesFromDB(objConn,strTable,RS("MenuID"),intDepth)
				RS.MoveNext
			Loop
			RS.Close
		End If
		Set RS = Nothing
	End Sub
	-->

Open in new window

0
Comment
Question by:alateos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:alateos
ID: 24798144
I think the change needs to be done here:

For Each objFile In objFolder.Files
                  Out "<li class=file>" & objFile.Name & "</li>"
            Next
0
 
LVL 9

Expert Comment

by:rg20
ID: 24798476

to elaborate a bit

you should be able to extract the path from the objfolder object

For Each objFile In objFolder.Files
        <a href="file:///extract path here">filename</a>
next
0
 

Accepted Solution

by:
alateos earned 0 total points
ID: 24798500
Actually, I used filename.shortpath and it worked
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question