Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Web
Expertise: Intermediate
Feb 12, 1999

Creating an HTML Directory in ASP

Although most Web servers give you the option of allowing users to view the list of files in a Web site directory, you may not want to show some types of files. Also, you may want to present the list of files in attractive table. The following code, written for Internet Information Server with Active Server Pages (ASP), displays all of the GIF files in the directory C:\inetpub\wwwroot\work. It also shows the size of the file, the type, the date that it was last accessed, and when it was last modified. Update the variables called thepath and thefile to reflect your Web's path and the type of file that you want to display.
 
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<!--Ken Cox kenc@corinet.com January 1999-->
<TITLE>Directory</TITLE>
</HEAD>
<BODY>
<CENTER>
<TABLE background="" bgColor=#99cccc 
border=1 borderColor=#669999 
borderColorDark=#ffffff borderColorLight=#000000 
cellPadding=4 cellSpacing=1>
<tr>
<th>File</th><th>Size</th>
<th>Type</th>
<th>Accessed</th>
<th>Modified</th>
</tr>
<%
dim thepath, thefile
thepath="c:\inetpub\wwwroot\work\"
thefile=".gif"

Set fs = CreateObject("Scripting.FileSystemObject")
Call ShowFolderList(thepath)
Set fs=Nothing

Sub ShowFolderList(folderspec)
On error resume next
Set f = fs.GetFolder(folderspec)
Set fc = f.Files 
For Each f1 in fc
If instr(1,ucase(f1.name),ucase(thefile)) Then
Response.Write "<tr>"
Response.Write "<td><a href='" & f1.name & "'>" & f1.name & "</a></td>"
Response.Write "<td>" & f1.size & "</td>"
Response.Write "<td>" & f1.type & "</td>"
Response.Write "<td>" & f1.DateLastAccessed & "</td>"
Response.Write "<td>" & f1.DateLastModified & "</td>"
Response.Write "</tr>" 
End If
Next
End Sub
%>
</TABLE>
</CENTER>
</BODY>
</HTML>
Ken Cox
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date