In a World Of Databases, ASP and Text Files
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("<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.

NEXT

Stuff

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
http://www.mallard-design.com/
Copyright 1999 Thomas Mallard, USA

 

Close    To Top
  • Prev Article-Web Design:
  • Next Article-Web Design:
  • Now: Tutorial for Web and Software Design > Web Design > ASP > Web Design Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction