472,141 Members | 1,218 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,141 software developers and data experts.

list documents in a html table

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
Jul 19 '05 #1
5 2661
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

"Ken" <kl*****@spamfreeingr.com> wrote in message
news:uk**************@TK2MSFTNGP12.phx.gbl...
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

Jul 19 '05 #2
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.
-----Original Message-----
I currently have a set of documents in a directory that i need to list in ahtml table. Is there any way to generate the table with the documents listedinstead of having to update the table manually everytime a new document isadded to the list.

Thanks
Ken
.

Jul 19 '05 #3
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
"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:um*************@TK2MSFTNGP11.phx.gbl...
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

"Ken" <kl*****@spamfreeingr.com> wrote in message
news:uk**************@TK2MSFTNGP12.phx.gbl...
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


Jul 19 '05 #4
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


"Ken" <kl*****@spamfreeingr.com> wrote in message
news:uq**************@TK2MSFTNGP11.phx.gbl...
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
"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:um*************@TK2MSFTNGP11.phx.gbl...
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

"Ken" <kl*****@spamfreeingr.com> wrote in message
news:uk**************@TK2MSFTNGP12.phx.gbl...
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



Jul 19 '05 #5
On Tue, 22 Jul 2003 10:36:25 -0500, "Ken" <kl*****@spamfreeingr.com>
wrote:
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
Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Neil Varshneya | last post: by
9 posts views Thread by Stephen Tyndall | last post: by
33 posts views Thread by abs | last post: by
12 posts views Thread by enak | last post: by
69 posts views Thread by markarichman | last post: by
9 posts views Thread by Thomas Ploch | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.