Tutorials to .com

Tutorials to .com » Asp » Skills » With ASP to achieve the directory tree view

With ASP to achieve the directory tree view

Print View , by: iSee ,Total views: 3 ,Word Count: 1877 ,Date: Sun, 26 Apr 2009 Time: 2:48 PM

Windows operating system resource management is very successful Microsoft document management software. It left the entire file system tree view, the right side of the paper is the current directory (folder) list for the document management provides a simple, easy-to-use user interface. However, Microsoft's IE browser but did not provide a similar function, if through the browser-based / Web server architecture to provide users with a Windows-Explorer is similar to the remote file management tool, will greatly facilitate the users. Based on this consideration, I use asp technology to achieve a resource management with Windows Explorer is similar to the remote file browser. This article describes one directory tree view, list view documents and files search that part of the three main methods to achieve.
Default.asp file This file is the main document used to structure the framework of the interface.
<html>
<head> <title> Welcome </ title> </ head>
<frameset rows="80,20*" framespacing="0">
<frame name = "pMain" scrolling = "auto" noresize
target = "contents" marginwidth = "1" marginheight = "1" src = "pMian.htm">
<frameset cols="230,530">
<frame name = "pTreeView" src = "pTreeView.asp?
VFdPath = <% = Request ( "VFdPath ")%>& Mflag =" scrolling = "1" marginwidth = "1" marginheight = "1" noresize auto "1">
<frame name = "pListView" src = "pListView.asp?
VFdPath = <% = Request ( "VFdPath ")%>" scrolling =" 1 "marginwidth =" 1 "marginheight =" 1 "noresize auto" 1 ">
</ frameset> <noframes> <body>
<p> because your browser does not support the framework of this page, you can not view this page </ p>
</ body> </ noframes> </ frameset> </ html>
pTreeView.asp document This document is mainly responsible for the generation of the directory tree view. Its core function FoldOpen (), is responsible for responding to user's directory operations, such as opening a folder and so on. Three parameters as follows:
● sflups: the current absolute virtual path;
● rsfd: the current physical path;
● dep: the depth of the current path (used to record the depth of recursion).
In this function also calls another function UnMapPath (), it will return the physical path corresponding to the virtual path (Note: The procedures in this article, all shared files are mapped to the virtual directory under the gpdir).
<%
vfd = Request.QueryString ( "VfdPath")
Mflag = Request.QueryString ( "Mflag")
Server.ScriptTimeout = 500
On Error Resume Next
Set obfs = Server.CreateObject
( "Scripting.FileSystemObject")
Set obfd = obfs.GetFolder (Server.MapPath ( "/ gpdir"))
oblength = Len (obfd.path)
Function UnMapPath (Path)
S = Mid (Path, oblength +1)
UnMapPath = Replace (S, "\", "/")
End Function
Function FoldOpen (sflups, rsfd, dep)
sPic = "<img border = 0 src =" "PIC / pSub.gif" "
width = 16 height = 16> "
if dep <> 0 then
spib = "<a href =" "pTreeView.asp? VFdPath ="
& "/ Gpdir /" & UnMapPath (rsfd.Path)
else
spib = "<a href =" "pTreeView.asp? VFdPath =" & "/ gpdir" & UnMapPath (rsfd.Path)
end if
spib = spib & "& Mflag ="
spib = spib & "c" "TARGET =" "pTreeView" ">"
Response.Write spib & sPic & "</ a>"
sPic = "<img border=0 src=""PIC/pOpen.gif"" width=16 height=16>" & rsfd.Name
spib = "<a href =" "pListView.asp? VFdPath ="
if dep <> 0 then
spib = spib & "/ gpdir /" & UnMapPath
(rsfd.Path) & "" "TARGET =" "pListView" ">"
else
spib = spib & "/ gpdir" & UnMapPath (rsfd.Path) & "" "TARGET =" "pListView" ">"
end if
Response.Write spib & sPic & "</ a> </ TD> </ TR>"
for each sfd in rsfd.SubFolders
Response.Write "<TR> <TD class=p9 height=16 width=""100%"">"
for cn = 0 to dep
Response.Write "<img border=0 src=""PIC/pline.gif"" width=16 height=16>"
Next
if sfd.SubFolders.count> 0 then
if InStr (1, sflups, "/ gpdir /" & UnMapPath (sfd.Path), vbTextCompare) <> 1 then
sPic = "<img border = 0 src =" "PIC /
pAdd.gif "" width = 16 height = 16> "
spib = "<a href =" "pTreeView.asp? VFdPath =" & "/ gpdir /" & UnMapPath (sfd.Path)
spib = spib & "& Mflag ="
spib = spib & "o" ""
spib = spib & "TARGET =" "pTreeView" ">"
Response.Write spib & sPic & "</ a>"
sPic = "<img border=0 src=""PIC/pClose.gif"" width=16 height=16>" & sfd.Name
Response.Write "<a href =" "pListView
. asp? VFdPath = "&" / gpdir / "& UnMapPath (sfd.Path) &" "" TARGET = "" pListView ""> "& sPic &" </ a> </ TD> </ TR> "
else
scdep = dep +1
FoldOpen sflups, sfd, scdep
end if
else
Response.Write "<img border=0 src=""PIC/pmline.gif"" width=16 height=16> "
sPic = "<img border = 0 src =" "PIC / pClose.gif"
"Width = 16 height = 16>" & sfd.Name
Response.Write "<a href =" "pListView.asp?
VFdPath = "&" / gpdir / "& UnMapPath (sfd.Path) &" "" TARGET = "" pListView ""> "& sPic &" </ a> </ TD> </ TR> "
end if
next
End Function
%>
<html>
<head> <title> folder </ title>
<base target="main"> </ head>
<body bgcolor="#008080" text="#FFFFFF">
<TABLE Align=left border=0 cellPadding=0 cellSpacing=0 width="100%">
<TR> <TD Width="100%">
<img border="0" src="PIC/pFolder.gif">
</ TD> </ TR> <TR>
<TD Height=16 width="100%">
<%
if Request ( "VFdPath ")="" then
FoldOpen "/ gpdir", obfd, 0
else
if Request ( "Mflag") = "c" then
if Request ( "VFdPath") <> "/ gpdir" Then
vfps = Request ( "VFdPath"
Set scobfd = obfd.GetFolder (Server.MapPath (vfps))
obfd = scobfd.ParentFolder
FoldOpen "/ gpdir /" & UnMapPath (refd), obfd, 0
else
sPic = "<img border = 0 src =" "PIC /
pAdd.gif "" width = 16 height = 16> "
spib = "<a href =" "pTreeView.asp? VFdPath = / gpdir"
spib = spib & "& Mflag ="
spib = spib & "o" ""
spib = spib & "TARGET =" "pTreeView" ">"
Response.Write spib & sPic & "</ a>"
sPic = "<img border = 0 src =" "PIC /
pClose.gif "" width = 16 height = 16> "& obfd.Name
Response.Write "<a href=""pListView.asp?VFdPath=/gpdir"" TARGET=""pListView""> "& sPic &" </ a> </ TD> </ TR> "
end if
else
FoldOpen Request ( "VFdPath"), obfd, 0
end if
end if
%>
</ table> </ body> </ html>
pListView.asp paper is mainly responsible for the document to generate a document list view and respond to the user in the view of the operation. Due to space limitations, here only its main function is given FileLink (f), it is used to generate documentation of the link corresponding to f.
Function FileLink (f)
FileLink = "<tr> <td> <A HREF =" "" & "GetFl.asp? VFdPath =" & vfdir & "/" & f.Name & "&"
FileLink = FileLink & "Sz =" & f.Size \ 1024 & "" & """>"& f.Name & "</ A> </ td>"
FileLink = FileLink & "<td>" & f.Size \ 1024 & "KB </ td>"
FileLink = FileLink & "<td>" & f.Type & "</ td>"
FileLink = FileLink & "<td>" & Mid
(f.DateLastModified, 1,10) & "</ td> </ tr>"
End Function
SchEnd.asp document is responsible for the document in response to a document search, and the results of the search form with the list of files displayed to the user. As a result of whether there is a subdirectory the current directory, a subdirectory the total number of layers (ie, depth) are unknown, so it is necessary to use a better algorithm, to achieve the level of subdirectories to display and search. Taking into account the recursive directory tree itself, and this paper, recursive algorithm. Search function is as follows:
Sub SearchFolder (fd, fl)
For each f In fd.Files
If InStr (1, f.Name, fl, vbTextCompare)> 0 Then
Response.Write FileLink (f)
End If
Next
For each sfd In fd.SubFolders
SearchFolder sfd, fl
Next
End Sub
This function fd in the folder and its subfolders, the recursive search string contains the file name of the file fl and the corresponding link to the user.
GetFl.asp document
<%
vfd = Request.QueryString ( "VfdPath")
Response.Redirect vfd
%>
GetFl.asp only two lines of code into a separate document the reason why is because as long as the increase in this file the appropriate filter code, the whole system can achieve greater functionality, such as: traffic records, statistics, download the file.


ASP skills Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.