|
|
 |
Lesson 12: File archive
Summary:
Learn how to use VBScript to make an easy to update file archive.
View the result
Intro:
I often got some archive of files that I would like to share
over the internet. I make a dir, drop my files in it, and
make an HTML index file listing all the files with links.
But when I want to add, or remove some files from the archive,
I have to update the HTML file as well. Or do I?
File Access Component
Through the File Access Component built into IIS and PWS
I can make a listing of all the files in a folder.
I just make an ASP page that lists all the files in my
archive folder. And when the content of the folder
changes, I don't need to update the ASP file.
This makes it so easy to maintain that any one can
update the file archive. Just drop the new files
in the right folder, and boom they're online!
(So easy that your boss could do it!).
Alternatives
You could just turn "directory browsing" on in IIS or PWS,
or set up an FTP server. But this solution
is easier to set up and maintain than FTP, is safer than
"directory browsing" and best of all: You control the layout!
The code:
<HTML>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#000000" VLINK="#000000">
<BR>
<B>My file archive:</B><BR><BR>
<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0>
<TR BGCOLOR="#000000">
<TD><FONT COLOR="#FFFFFF"><B>Filename:</B></FONT></TD>
<TD><FONT COLOR="#FFFFFF"><B>Size:</B></FONT></TD>
<TD><FONT COLOR="#FFFFFF"><B>File type:</B></FONT></TD>
<TD><FONT COLOR="#FFFFFF"><B>Date created:</B></FONT></TD>
<%
' Create an instance of the FileSystemObject
Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")
' Create Folder Object
Set MyFolder=MyFileObject.GetFolder(Server.MapPath("shared"))
'Loop trough the files in the folder
FOR EACH thing in MyFolder.Files
%>
<TR BGCOLOR="#F7F7E7">
<TD><A HREF="shared/<%=thing.Name%>"><%=thing.Name%></A></TD>
<TD ALIGN=RIGHT><%=thing.Size%>bytes</TD>
<TD><%=thing.Type%></TD>
<TD><%=thing.DateCreated%></TD>
<%
NEXT
%>
</TABLE>
</BODY>
</HTML>
View the result.
Download code
Where to go next:
Take a look at our lessons page
to get an overview of all our lessons.
| |
|
|
 |
|