<%
Option Explicit
Dim fso, folders, files
Dim pathname
If Request.QueryString("filepath") <> "" Then
pathname = Request.QueryString("filepath")
Else
pathname = "/"
End If
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set folders = fso.getFolder(Server.Mappath(pathname))
Set files = folders.files
Dim previewable
previewable = "asp htm html xml xsl jpg gif txt csv"
Dim file, types, fn
For each file in files
fn = right(file.name,len(file.name) - InStr(file.name,"."))
If InStr(types,fn) < 1 Then
types = types & fn & "#"
End If
Next
Dim filetypes
fileTypes = split(types,"#")
Dim content
content = split(types,"#")
Dim i
For i = 0 to UBound(content) - 1
content(i) = "<tr class='rowHeader'><td colspan='4' align='center'>"&ucase(fileTypes(i))&" Files</td></tr>"
Next
dim ind,sz
For each file in files
ind = getIndex(file.name)
If file.size > 1024 Then
sz = Round(file.size/1024,2) & " KB"
Else
sz = file.size & " bytes"
End If
content(ind) = content(ind) & "<tr><td>"
If InStr(previewable,fileTypes(ind)) Then
content(ind) = content(ind) & "<input type=""button"" onClick=""document.getElementById('fraPreview').src='"&pathname&file.name&"'"" value=""Preview"" class=""btnPreview"">"
End If
content(ind) = content(ind) & "</td><td>" & file.name & "</td><td align='right'>" & sz & "</td><td align='right'>" & file.dateLastModified & "</td></tr>"
Next
Function getIndex(filename)
Dim en, i
en = right(file.name,len(file.name) - InStr(file.name,"."))
For i = 0 to UBound(fileTypes) - 1
If lcase(en) = lcase(fileTypes(i)) Then getIndex = i
Next
End Function
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Previewing Files</title>
<style>
table{
background-color:#999999;
}
table tr{
background-color:#eeeeee;
}
.rowHeader{
background-color:#cccccc;
}
iframe{
border:2px #999999 solid;
}
</style>
<style media="print">
iframe{
display:none;
}
.btnPreview{
display:none;
}
</style>
</head>
<body>
<table width="90%">
<tr>
<td colspan="6" align="center">
Directories
</td>
</tr>
<%
' Dim f, c
' c = 0
' For Each f In folders.getFolders
' If c mod 6 = 0 Then Response.Write "<tr>"
' Response.Write "<a href=""xmlDirListing.asp?pathname="&pathname&"/"&f.name&""">"&f.name&"</a>"
' If c mod 6 = 5 Then Response.Write "</tr>"
' c = c+1
' Next
%>
</table>
<table width="90%">
<tr>
<td>
Preview
</td>
<td>
Filename
</td>
<td>
Size
</td>
<td>
Last Modified
</td>
<td valign="top" rowspan="<%=UBound(fileTypes)+files.count+1%>">
Preview Window<br>
<iframe id="fraPreview" height="100%" width="100%"></iframe>
</td>
</tr>
<%
Dim section
For each section in content
Response.Write section
Next
%>
</table>
</body>
</html>