-Log in
-Register (free)

-RSS Feeds
-New MyDesk Module
-Update to Profile

Alternate color for RS looping with For Next
Northwind / ASP - Nested select
ASP SQL Injection

 Lesson 12: File archive
Lesson 12: File archive

Author: Alexander Haneng
Difficulty: Easy
Requires: ASP
Demo: demo
Download: Lesson12.zip
Learn how to use VBScript to make an easy to update file archive. View the result

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!).

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:
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#000000" VLINK="#000000">
<B>My file archive:</B><BR><BR>
<TR BGCOLOR="#000000">
<TD><FONT COLOR="#FFFFFF"><B>Filename:</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
<TD><A HREF="shared/<%=thing.Name%>"><%=thing.Name%></A></TD>
<TD ALIGN=RIGHT><%=thing.Size%>bytes</TD>

View the result.
Download code

Where to go next:
Take a look at our lessons page to get an overview of all our lessons.

11: VBScript functions
13: VBScript forms
| Info |
© Copyright 1997-2016 Alexander Haneng