how to articles

"Let The Computer Do The Work" series

(note: this article is a work in progress and was last updated 26-May-2005 . check back soon for the latest updates.)

Building Content using Folders and the Files In Them
using ASP FileSystem Object
(PHP coming soon)

STEP 3 Automatically Link To Files

3. Add code to build links to those files on the fly.

The purpose of this step is to use the list of File names created in the code in Step 2 to build to the HTML to link to each of these Files in turn. With a line or two of code, you can generate 5 or 20 or even 1000 links based solely on the number of Files in the Folder.

After completing Step 2, we have an array of all the File names from our Folder. Now, we want to create text links in our Web page linking to each of those Files. Since we gave the Files meaningful names in Step 1, we can use those names to create the text links.

So that the links have some structure on the Web page, I'm going to add an HTML TABLE to hold our links. This is not ASP code, but the ASP code shown below will generate the TABLE cells (TD Tags) to hold the individual links. There will be only one TABLE cell per TABLE row.

HTML for TABLE (beginning)

<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>

ASP Code to Create Text Links

<%
idx = 0
for each car in ImgArray
%>
<TR><TD><A HREF="carimages/<%=car)%>" TARGET="_blank">
<%= LEFT(car, (LEN(car) - 4))%></A></TD></TR><%
next
%>

HTML for TABLE (ending)

</TABLE>

The code above creates a table row for each link. In the table cell is a text link to each image (each File in our Folder). The text itself is the File name without the file extension (.jpg), and the link when clicked opens in a separate browser window. The only change you might need to make is the Folder name ("\carimages") in the line beginning with "<TR><TD>."

and the next step is Step 4...