dcsimg

In a World Of Databases, ASP and Text Files

By ServerWatch Staff (Send Email)
Posted Jan 24, 1999


T.Mallard


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.


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.

Output from this code.
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("<html>")
response.write("<head><title>Website Navigation Page</title>")
response.write("</head>")
response.write("<body>")
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>")
wend

response.write("</table></body>")
response.write("</html>")
navfile.close
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.

Page 1 of 3


Comment and Contribute

Your name/nickname

Your email

(Maximum characters: 1200). You have characters left.


 

 


Thanks for your registration, follow us on our social networks to keep up-to-date