GuidesIn a World Of Databases, ASP and Text Files

In a World Of Databases, ASP and Text Files

ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.




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 7×24 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:websharewwwrootaspnav.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:

homepage
products
prices
technical
white papers
support
archive

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="%22%20&%20nav%20&%20%22%20″ target=”main”>” & nav & ““)

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:websharewwwrootaspnav.txt“)
end if
response.write(““)
response.write(““)
response.write(“Website Navigation Page“)
response.write(““)
response.write(““)
response.write(“

“)
while not navfile.atendofline
dim nav = navfile.readline
response.write(“

“)
wend

response.write(“

=’ ” & nav & “ ‘target=’main’>” & nav & “

“)
response.write(““)
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.

Get the Free Newsletter!
Subscribe to Daily Tech Insider for top news, trends & analysis
This email address is invalid.
Get the Free Newsletter!
Subscribe to Daily Tech Insider for top news, trends & analysis
This email address is invalid.

Latest Posts

Related Stories