list documents in a html table

K

Ken

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.

Thanks
Ken
 
R

Ray at

Where is this directory? Is it on the IIS server? I'm going to assume for
the moment that the directory is on the IIS server. There are at least two
options. 1 is to just enable directory browsing for the directory and not
have a default page for the directory (default.htm, default.asp, etc.). If
you'd like to make things prettier, you can use the FSO and do something
like:

<table>
<tr>
<td>File name</td>
<td>Last modified</td>
</tr>

<%
Dim oFSO, oFiles, oFile
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
Set oFiles = oFSO.GetFolder("D:\PathOnServer").Files
For Each oFile in oFiles
%>
<tr>
<td><%=oFile.Name%></td>
<td><%=oFile.DateLastModified%></td>
</tr>
<%
Next

Set oFiles = Nothing
Set oFSO = Nothing
%>
</table>

IUSR will need permission to read the directory if you're using anonymous
access on your site (default).

Ray at work
 
C

Clive

Ken,

How about you save them in a database table.

Quewry your table and loop through each record
interweaving it with HTML and that would save you
changing your HTML code each time.
 
K

Ken

Thanks for the response.
This is just what I need. One more question. How can I create a link to the
files after they are listed so that they can be opened up?

Thanks again
Ken
 
R

Ray at

Generate the HTML that would provide a link. What do you want the resultant
HTML to look like? You'd want it to look like:


<td><A href="filex.doc">filex.doc</a></td>

right? What is filex.doc? It's the current .Name property of the current
file while looping. So, to get that resultant HTML, you'd do:


'''other code
For Each oFile in oFiles
%>
<tr>
<td><A href="<%=oFile.Name%>"><%=oFile.Name%></A></td>
<td><%=oFile.DateLastModified%></td>
</tr>
<%
Next
'''other code


Ray at work
 
J

Jeff Cochran

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,078
Messages
2,570,572
Members
47,204
Latest member
MalorieSte

Latest Threads

Top