Ahh, well now it gets really interesting...
There isn't any
server object to play with here just for starters, and thus no
mappath method. Your script runs at the client (in the browser). Even if there
were some way to get that filename, you can't read it with
FSO. At best (relaxed security settings in the browser, security warning popup dialog and the user says "ok"

you can only read local files (on the client machine) this way.
1. Are you trying to build some sort of "client-side include" function?
2. Is the text file stored as part of your web site (in the root of your web site or a subfolder)?
3. Is it really text, and not HTML?
4. Is it static, only updated when you publish a new text file?
If all of these are "yes" - and for (4.) maybe even if "no" (i.e. it is HTML and not plain text), you just
might be able to do this using an IE component called the
Tabular Data Control (
TDC). TDC (unlike FSO) was designed to be used client-side to fetch a text file from the server, and then let you do what you want with the data at that point. But TDC can't
write back to the server.
TDC was intended to be used with
data binding, an IE feature you may not be familiar with. The basic idea is that the text file contains tabular data, like a database table, arranged like a CSV data file. The columns (or fields) in the data file get "scooped up" off the server and held in the TDC. Then in your HTML you can define things like
<table>s to be
data-bound to the TDC. This means IE will build the <table> up from the data in the TDC. You only define things like
row templates (
<tr>-type rows) and IE repeats the row template as many times as needed to display all the data in the TDC. There is even some cool stuff to automagically
page through the data, showing say 10 records at a time and letting the user click on buttons to page forward and back through it - all at the browser.
The basic TDC reference can be found at:
Also see:
For data binding see:
And...
And...
Now what you want to do sounds different. You just want to grab the text (or HTML) from the server and plop it into your page to show it, right?
Well TDC can be "fooled" into doing this too.
More typically you would tell TDC what the field delimiter (normally "," or vbTab) and record delimiter (normally vbNewLine) are, along with what if anything to treat as "quotes" around text values (normally a """" - i.e. a single " a.k.a. Chr(34)).
If your text file has no "|" or "~" in it, tell it the field delimiter is the "|" character and the quote character is "~" and the record delimiter is vbNewLine (default). This means each line of text is fetched into TDC as a single-field row. Then process the rows much like reading lines from a text file via FSO.
If you want to suck in the whole file at once, put some symbol as the very last char of the file, tell TDC this thing is your record delimiter, tell TDC something else bogus is your field delimiter and quote value. This will make it take in the whole file as one, one-field row, with the VBNewLines (CR/LFs) embedded in the value. Then pull out this "field" from this "first row" and do as you wish with the string you get.
I've seen people define the quote to be Chr(&HFD), the field delimiter to be Chr(&HFE), and the row/record/line delimiter to be Chr(&HFF). Then they put a Chr(&HFF) at the end of the file and let the other two weird characters just be there (though not in the text of the file) just to keep TDC happy... keep it from breaking things up into lines and fields. You could use Chr(&HFD) and Chr(&HFE) yourself and then use "|" as the row delimiter. EAsier to get into a text file usually than Chr(&HFF).
You do
not have to use TDC with data binding - that's just what it was really made for. See:
That article shows you what doesn't seem to be given in the reference materials (at the links above) on TDC. This secret is that TDC has a
recordset property you can use like:
Code:
Dim objRS, strData
Set objRS = objTDC.recordset
objRS.MoveFirst
strData = objRS(0)
Set objRS = Nothing
[code]
This sample assume a TDC called objTDC is already loaded. It pulls out the value of field 0 of the first record/row in the TDC's recordset, and puts it into strData so we can play with it. As I said, no data binding is needed - you can mess with the data much as if objRS were a regular ADO Recordset object.
A lot to absorb, but hey! You trying to get tricky, it takes some trickyness.
Final comment:
I'd really avoid [COLOR=blue]document.write[/color] if possible. It works, but it can be nasty. If it does what you want fine, but normally I would declare a named [COLOR=blue]<div>[/color] or [COLOR=blue]<span>[/color] and set either its [COLOR=blue]innerText[/color] or [COLOR=blue]innerHTML[/color] properties.
[code]
:
<object id="objTDC" classid=....
<param name=...
<param name=...
</object>
:
:
<script>
Sub window_onload()
Dim objRS, strData
Set objRS = objTDC.recordset
objRS.MoveFirst
strData = objRS(0)
Set objRS = Nothing
divInclude.innerHTML = strData
End Sub
</script>
:
:
<body>
<p>beginning</p>
<div id="divInclude">
on page load we put strData here
Code:
</div>
<p>end</p>
</body>
</html>
Good luck! A lot to bite off, hmm?
Anybody else got ideas on this?