If you want a method that works
without some sort of dynamic server technology such as ASP, CGI, PHP, etc. your options are more limited. I'll assume since you posted here in VBScript you can live with an IE-only solution.
IE comes with a very handy component called the Tabular Data Control (TDC). This is meant for use with IE data binding, but you can also access the data directly from script via the TDC object's
property as well if you choose.
The idea behind TDC is for the page to fetch text file content containing tab or comma delimited text.
By setting the delimiters to unlikely values and "nulling out" the "quote" or TextQualifier though, the TDC can bring back the whole text file as "one row, one column" - or in other words one big blob of text.
Depending on what your text file contains and how you want to display it, you might be way ahead to let it carve the file into rows or records and one or more fields. Then use data binding or the recordset to arrange for displaying it. Data binding to <TABLE>s makes some fancy stuff pretty easy though.
Hmm... just displaying the text is easy. You want to format it yourself though? A little bit more effort, not much:
Code:
<HTML>
<HEAD>
<TITLE>Load text via TDC</TITLE>
<OBJECT id=objTDC
classid=clsid:333C7BC4-460F-11D0-BC04-0080C7055A83>
<PARAM NAME="RowDelim" VALUE="&#ff;">
<PARAM NAME="FieldDelim" VALUE="&#fe;">
<PARAM NAME="TextQualifier" VALUE="">
<PARAM NAME="DataURL" VALUE="some.txt">
</OBJECT>
<SCRIPT language=VBScript>
Sub btnDisplay_onclick()
divDisplay.innerHTML = _
Replace(divText.innerText, vbCrLf, "<BR>")
End Sub
</SCRIPT>
</HEAD>
<BODY>
<H1>All text loaded from file as one row, one column</H1>
<DIV id=divText datasrc=#objTDC datafld=Column1
style="display: none">
</DIV>
<INPUT type=button id=btnDisplay value="Display Text"><BR>
<DIV id=divDisplay>
</DIV>
</BODY>
</HTML>
As I said, simple.
This example uses an instance of TDC to load a file called
from the server. You can test it locally by making some folder, creating a file
in it. Then create a file called something like
in this folder and paste the code above into it.
When you load this web page, the TDC will pull in the text file data as one record (row) and field (column), and using data binding will put it into the hidden <DIV> I have called
. Note that since I haven't done anything fancy, the first field gets the default name
.
If you click on the button
the onclick handler written in VBScript will pull the text out of
, reformat it, and place it into
. In this case I didn't get fancy, I just changed all of the vbCrLf pairs into HTML line breaks.
This works from file locations, i.e. locally, or from a web server. One caveat has to do with cross-domain access: there are security features in TDC to permit or restrict that. The TDC also has to be able to "see" the text file: TDC needs to be able to pull the data via
FILE://, FTP://, or some other URL protocol. TDC gets data the same ways that IE gets data.
You can find more on TDC at:
Sadly, further information on TDC is harder to find - though I have seen a number of MSDN articles on the subject over the years. It is one of the best reasons I ever found to say "forget Netscape" which doesn't offer anything remotely similar or as useful for making interactive web sites without dynamic server capabilities.
Oh yeah - TDC can't write back to the server or text file. Just thought I'd add that little bit. It is
great for reporting functions though. I have even use TDC with data binding and things like the MS Chart control to provide dynamic graphical reports without needing ASP or CGI - and no
steenking Java either. ;-)