Click to See Complete Forum and Search --> : Read/write a txt file


cacalex
05-12-2003, 02:01 PM
Hi,

I need an javascript able to read text in a ".txt" file...

I've test the "Scripting.FileSystemObject" without sucess...

HEEEEEEEEEELLLLLLLLLLPPPPPPPP !!!!

:confused:

Nevermore
05-12-2003, 02:08 PM
On the server or on the client's machine?

cacalex
05-12-2003, 02:30 PM
Actually, only on the client machine,

But i'm interest in both...

Thanks

Jona
05-12-2003, 02:33 PM
You can use the FSO (FileSystemObject) object to create, edit, read, append to, etc., .txt files on the user's local machine. Although this prompts the user to agree to use ActiveX, I'm sure you know that. ;) The FSO cannot be used on the server, because JavaScript is client-side and not server-side, it has no access to the server.

cacalex
05-12-2003, 02:36 PM
OK...

can you provide me some codes examples, so i can test it.

Like i previously write, i already test the FSO method, but i just can't make it work....

Thanks !

khalidali63
05-12-2003, 02:39 PM
Writing to a file on a local machine from client is considered a securiyt problem,anything of that sort is well suited by a server side programming language.

Jona
05-12-2003, 02:40 PM
Certainly:

var fso = new ActiveXObject("Scripting.FileSystemObject");
var a = fso.CreateTextFile("c:\\testfile.txt", true);
a.WriteLine("This is a test.");
a.Close();

cacalex
05-12-2003, 02:42 PM
Thanks Jona,

But if i understand well this example, it is actuallu writting text in a file...

How can i get the text back after that ???

Jona
05-12-2003, 02:45 PM
function GetLine()
{
var fso, f, r;
var ForReading = 1, ForWriting = 2;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.OpenTextFile("c:\\testfile.txt", ForWriting, true);
f.WriteLine("Hello world!");
f.WriteLine("JavaScript is fun");
f.Close();
f = fso.OpenTextFile("c:\\testfile.txt", ForReading);
r = f.ReadLine();
return(r);
}

cacalex
05-12-2003, 02:53 PM
AAAAAAAHHHHHHHHHH !!!

It's working !

Can't believe it !

I Pass three days trying to make this work !

You Shall be the worship one !!!

Thanks !!

I'll be in debt forever...

Jona
05-12-2003, 02:54 PM
:D {Thank Microsoft, too. LOL}