cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
671
Views
0
Helpful
6
Replies

Opening/Reading txt file using JavaScript

paul.knapp
Level 1
Level 1

Hi,

I want to use JavaScript to open/read TXT file and display content on the screen of the IP Phone.

This is my testing program:

set fs=CreateObject("Scripting.FileSystemObject");

set wfile=fs.OpenTextFile("zzz.txt");

wfile.close;

...but it does not work. I get HTTP 500 error.

When I use other java functions like Response.Write(), it works fine.

Is it something I have to do to have this thing working ?

Need to load java libraries ?

Paul

6 Replies 6

esther.burger
Level 1
Level 1

Hello Paul,

first of all I would like to say that I cannot help you with your problem. Sorry!

I only would like to know if you found a solution for your problem in the meantime, because I have the same problem and cannot solve it.

So if you found a solution it would be really kind of you to publish your results in the forum.

Thanks!

Sascha Monteiro
Level 6
Level 6

Hi,

Are you running it in .asp?

have you tried something like this?

<%

Set fs=Server.CreateObject("Scripting.FileSystemObject")

Set f=fs.OpenTextFile(Server.MapPath ("testread.txt"), 1)

Response.Write(f.ReadAll)

f.Close

%>

..just tested and it worked...

Hello,

in the meantime I cracked it too, but thank you very much for your help.

I found a very good website (http://www.html-world.de/program/fso_3.php -> German) where all the different functions of the FileSystemObject are explained.

In this context I found out that my problem was not a wrong code, my problem was a lack of access rights to the txt-file :-).

That's quite a common mistake because webservers use a less privileged account. It's not such good practice to access files outside the restricted permissions though, unless properly done it can open holes in your security.

Hi,

Thank you for response.

Yes.I was running in asp. When I tested your sample script, I got HTTP error 404. Seems that first line is problamatic and the system does not know how to create the object.

Did you have to run something specific on WEB server or maybe extra processes to have this script correctly activated ?

Paul

Hello Paul,

in your first request you wrote that you use JavaScript in your asp-file. Or not?

Maybe then you should try something like this:

fso = new ActiveXObject("Scripting.FileSystemObject");

a = fso.GetFile('C:/Name.txt');

b = a.OpenAsTextStream(modus,format);

c = b.ReadAll();

modus = 1 (read only), 2 (write only), 8 (attach text)

format = -1 -> Unicode; 0 -> ASCII; -2 -> system configuration

I hope you'll find a solution.