I currently have a set of documents in a directory that i need to list in a
html table. Is there any way to generate the table with the documents listed
instead of having to update the table manually everytime a new document is
added to the list.
Here's how we serve up files from a folder dynamically:
<%
dim StringLength
dim TemporaryName
dim DisplayName
dirtowalk="/documents"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(server.mappath(dirtowalk))
Set fc = f.Files
response.write "<UL>"
For Each FileName in fc
StringLength = Len(FileName.name)
StringLength = StringLength - 4
TemporaryName = Left(FileName.name,StringLength)
DisplayName = Replace(TemporaryName,"_"," ")
response.write "<LI><A HREF='/documents/"
response.write FileName.name
response.write "'>"
response.write DisplayName
response.write "</A><br>"
Next
response.write "</UL>"
%>
No table, just a list of files without extensions, automatically
linked to the files. We normally publish in PDF format, try this link
for the end result:
http://manager.naplesgov.com/updates/2003.asp
I use this snippet quite a few places to serve up a list of documents
dynamically, but don't blame me for the code. I picked it up quite a
while ago and I'd credit the original author if I knew who it was.
Though I'm the one to blame for making the display pretty.
The code displays the file name, replacing underscores with spaces.
So we put the files to be served in the folder like this:
This_is_a_file.pdf
Here_is_Another.pdf
And so on. Adding table code into the loop isn't hard, something
like:
<%
dim StringLength
dim TemporaryName
dim DisplayName
dirtowalk="/documents"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(server.mappath(dirtowalk))
Set fc = f.Files
response.write "<TABLE CELLPADDING=2>"
For Each FileName in fc
StringLength = Len(FileName.name)
StringLength = StringLength - 4
TemporaryName = Left(FileName.name,StringLength)
DisplayName = Replace(TemporaryName,"_"," ")
response.write "<TR><TD><A HREF='/documents/"
response.write FileName.name
response.write "'>"
response.write DisplayName
response.write "</A></TD></TR>"
Next
response.write "</TABLE>"
%>
Change the dirtowalk variable to whatever directory you'll be using as
well as the appropriate HREF path.
Hope it helps.
Jeff