ASP 101 - Active Server Pages 101 - Web06
The Place ASP Developers Go!

Please visit our partners

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates

ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
What is ASP?
VBScript Classes: Part 1 of N
Migrating to ASP.NET

Fix for IIS security bug
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

In a World Of Databases, ASP and Text Files

Output from this code. Plain text files offer some advantages for online applications using changing data. The idea of this series of articles is to explain some of the better tricks for using plain text files, or comma and tab separated lists to support dynamic data sources for the internet. These concepts can be used for Enterprise platform hopping as well as small business needs. A basic premise of this work is that these data files are read-only to the world as typical HTML pages are. This prevents users from altering data and allows 7x24 on-the-fly updating using FTP by publishers.

The Latest
How do you keep all those messy pages up to date without a zillion concurrent users pounding your database? Like the idea of ad rotators, any site has a lot of dynamic data over time which can be reduced to classic (row,column) data. The best place to start for this is of course navigation, yet also consider ASP's Dictionary object in conjunction with text files to create easy to search, easy to update systems. This will also be explained in the series of articles.

Updating URL's for Navigation
Let's presume to have a navigation frame with links to other pages on the site. If these are kept in a text file and delivered dynamically to clients, they can also be used for other reasons by the website without altering the actual HTML pages. Using data this way increases exposure of your data which reduces the resource demand of keeping up to date.

Creating the Object
In this case, there is the need to create a file system object associated with the URL list. This is created using a readline routine that transfers the field into the navigation page as it is created. Typical code for this would look like:

dim objfile, navfile
set objfile = createobject("Scripting.FileSystemObject")

Does Object exist? If yes, open the file:

if isobject(objfile) then
set navfile = objfile.opentextfile("D:\webshare\wwwroot\asp\nav.txt")
An error can occur here if the file isn't found, or can't be opened by the system so having an 'on error' statement is important to keep the client application from hanging. To handle this error one could use a default list in memory which was included at runtime, or hard-coding URL's which are used on file system error. The entries for the text file or these alternatives would look something like:

<a href=" default.htm">homepage</a>
<a href="products.htm">products</a>
<a href="prices.htm">prices</a>
<a href="technical.htm">technical</a>
<a href="white_papers.htm">white papers</a>
<a href="support.htm">support</a>
<a href="archive.htm">archive</a>

The code now has nav.txt open in read-only mode if there wasn't an error. To read a line you code a statement:

while not navfile.atendofline
dim nav
nav = navfile.readline

Since this delivers the value we want for a URL, modify the statement to create a line of HTML output to the page.

response.write("<a href=' " & nav & " 'target='main'>" & nav & "</a>")

This is now ready to use in a loop which will create the links to pages which are going to be sent to the target frame "main". To send this page a typical HTML page is created with response writes.

<%@ language="vbscript" %>
<% response.buffer = True%>
dim objfile, navfile
set objfile = createobject("Scripting.FileSystemObject")
if isobject(objfile) then
set navfile = objfile.opentextfile("D:\webshare\wwwroot\asp\nav.txt")
end if
response.write("<!-- DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 3.2 Final//EN'-->")
response.write("<head><title>Website Navigation Page</title>")
response.write("<font face='verdana,arial,helvetica' size='2'><table border=0 cellpadding=6>")
while not navfile.atendofline
dim nav = navfile.readline
response.write("<tr><td bgcolor=ccffcc><a href=' " & nav & " 'target='main'>" & nav & "</a></td></tr>")

set objfile = nothing

What this code does
It creates a full HTML page which the top level frames page uses for navigation. The actual links used are from a text file somewhere on the server so to update them one simply replaces the text file. This is a simple example of using text files as an introduction to a very useful and versatile concept. The next article will build on this navigation page idea by explaining how to use this technique to fill select boxes.


Double quotes separated from single quotes for clarity, don't do this!
Previous versions of VBScript are CaseSensitive, this is written for the latest version.
Development Test System: Windows98, PentiumII 200MHz 128Mb
Personal Web Server 4.0 (IIS4), SQL7b3, Personal Oracle, Sybase

Author: T.Mallard, Seattle, WA
Copyright 1999 Thomas Mallard, USA


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers