PDA

Click to See Complete Forum and Search --> : JS: read a text file and output it


TvJames
Jan 16th, 2001, 05:57 AM
how can i read a plain text file then output it via document.write?

Jan 17th, 2001, 12:39 AM
Hi....

try the following sample code

function GetEverything()
{
var fso, f;
var ForReading = 1, ForWriting = 2;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.OpenTextFile("c:\\testfile.txt", ForWriting, true);
f.Write("Header");
f.Write("1234567890987654321");
f.Close();
f = fso.OpenTextFile("c:\\testfile.txt", ForReading);
document.write f.ReadAll
return(f.ReadAll());
}

Regards,
:o Mac :)

TvJames
Jan 17th, 2001, 12:43 AM
does the OpenTextFile function require the absolute path of the file??

Jan 17th, 2001, 02:31 AM
Hi ...James..

Sure it's need an absolute path ...

u can use
fso.GetAbsolutePathName(path)


Regards,
:o Mac :)

TvJames
Jan 17th, 2001, 03:08 AM
can this method read a file from the webserver or is it from the client machine?

because i need a replacement for <!--#include file""> ssi.

Jan 17th, 2001, 06:53 AM
Hi....
Yes but u need to do as below..

in ASP

<%
Set fso = Server.CreateObject("Scripting.FileSystemObject")

then code goes here ....
%>

If for Client Side, in VBScript

Set fso = CreateObject("Scripting.FileSystemObject")