视图Windows操作系统中的资源管理器是微软公司非常成功的文件管理软件。它的左边是整个文件系统的树形视图,右边是当前目录的文件(夹)列表,为文件管理提供了一个操作简单、使用方便的用户界面。但是,微软公司的IE浏览器却没有提供相类似的功能,如果能通过基于浏览器/Web服务器架构为用户提供一个与Windows 的资源管理器相类似的远程文件管理工具,将会极大地方便用户的使用。基于这种考虑,笔者用ASP技术实现了一个与 Windows 的资源管理器相类似的远程文件浏览器。本文介绍其中目录的树形视图、文件列表视图和文件搜索三个主要的部分的实现方法。
Default.asp文件 
此文件是主文件,用来构造整个界面的框架。  
<html> 
<head><title>欢迎光临</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>由于您的浏览器不支持此网页框架,所以您无法浏览此网页</p> 
</body> </noframes></frameset></html> 
pTreeView.asp文件 
此文件主要负责目录树形视图的生成。其核心函数为FoldOpen(),负责响应用户对目录的操作,如打开一个文件夹等。三个参数的说明如下: 
●sflups:当前的绝对虚拟路径; 
●rsfd:当前物理路径; 
●dep:当前路径深度(用来记载递归深度)。 
在此函数中还调用了另一个函数UnMapPath(),它将返回物理路径所对应的虚拟路径(注:在本文的程序中,所有共享文件都被映射到虚拟目录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=http://www.163design.net/a/q/““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=http://www.163design.net/a/q/““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=http://www.163design.net/a/q/““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=http://www.163design.net/a/q/““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=http://www.163design.net/a/q/““PIC/pmline.gif” ” width=16 height=16>” 
sPic=“<img border=0 src=http://www.163design.net/a/q/““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>文件夹</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=http://www.163design.net/a/q/“PIC/pFolder.gif”> 
</TD></TR><TR>  
<TD height=16 width=“100%”>  
用ASP实现树形目录视图
                    80酷酷网    80kuku.com 
       
  
 
 
  
