Reading a file

S

Steve

OK, I know I can't read a file with JavaScript, but I see references
that I can use the filesystemobject which is part of vb script. Can I
embed vb script in HTML?

I am writing a program for company internal use that will extract
information from a drawing on the user's local workstation and then
needs to convey that information to a web app communicating to the
user through their brower. Everything is pretty much microsoft tho'
we don't use IIS but are using the web serving capabilities of
weblogic.

Any suggestions for how to get that file's contents (probably less
than 1K) into the web app would be greatly appreciated. I don't mind
doing some digging here but point me in the right direction, please.

TIA

Steve
 
M

MikeB

Steve said:
OK, I know I can't read a file with JavaScript, but I see references

Not true. The FileSystemObject is availabel to JScript and JavaScript, instantiated as an ActiveX
object. For Internal use, look at putting your code in an HTA to avoid the Security constraints imposed
by the browser environment.
 
K

kaeli

swl773 said:
OK, I know I can't read a file with JavaScript, but I see references
that I can use the filesystemobject which is part of vb script. Can I
embed vb script in HTML?

Yes, but only IE understands it. I prefer JScript, and this is a
javascript group after all. JScript is also IE only. (It may work with
javascript, too, but I didn't check)
I am writing a program for company internal use that will extract
information from a drawing on the user's local workstation and then
needs to convey that information to a web app communicating to the
user through their brower. Everything is pretty much microsoft tho'
we don't use IIS but are using the web serving capabilities of
weblogic.

The server is irrelevant for reading client-side files.
Any suggestions for how to get that file's contents (probably less
than 1K) into the web app would be greatly appreciated. I don't mind
doing some digging here but point me in the right direction, please.

The following reads a text file from the user's (client) machine with
JScript and writes the contents to a div. Watch for word-wrap.
[note that the following generates an ActiveX warning]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title> Read client file with JScript </title>
</head>

<body>
<script language="JScript" type="text/jscript">

function ReadFile(filename)
{
var fso, f;
var ForReading = 1;
fso = new ActiveXObject("Scripting.FileSystemObject");

f = fso_OpenTextFile(filename,
ForReading);
txtbox.innerText = f.ReadAll();
f.close()
}

</script>
<BUTTON style="border: 1px outset; width:100px" onClick="ReadFile('c:
\\test.txt');">
Read File</BUTTON>
<div id="txtbox"></div>
</body>
</html>

I made a simple text file and saved it to c:\\test.txt.
Contents of text.txt:
this is a test file
with some contents in it
for testing
file IO

--
--
~kaeli~
Is it true that cannibals don't eat clowns because they
taste funny?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 
S

Steve

1I never heard of an HTA before but there seems to be plenty on the MS
web site. I'll look into it.

Thanks for the reply.
 
S

Steve

Thanks for the code. I got 2 good ideas to go on.

Thanks again.

swl773 said:
OK, I know I can't read a file with JavaScript, but I see references
that I can use the filesystemobject which is part of vb script. Can I
embed vb script in HTML?

Yes, but only IE understands it. I prefer JScript, and this is a
javascript group after all. JScript is also IE only. (It may work with
javascript, too, but I didn't check)
I am writing a program for company internal use that will extract
information from a drawing on the user's local workstation and then
needs to convey that information to a web app communicating to the
user through their brower. Everything is pretty much microsoft tho'
we don't use IIS but are using the web serving capabilities of
weblogic.

The server is irrelevant for reading client-side files.
Any suggestions for how to get that file's contents (probably less
than 1K) into the web app would be greatly appreciated. I don't mind
doing some digging here but point me in the right direction, please.

The following reads a text file from the user's (client) machine with
JScript and writes the contents to a div. Watch for word-wrap.
[note that the following generates an ActiveX warning]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title> Read client file with JScript </title>
</head>

<body>
<script language="JScript" type="text/jscript">

function ReadFile(filename)
{
var fso, f;
var ForReading = 1;
fso = new ActiveXObject("Scripting.FileSystemObject");

f = fso_OpenTextFile(filename,
ForReading);
txtbox.innerText = f.ReadAll();
f.close()
}

</script>
<BUTTON style="border: 1px outset; width:100px" onClick="ReadFile('c:
\\test.txt');">
Read File</BUTTON>
<div id="txtbox"></div>
</body>
</html>

I made a simple text file and saved it to c:\\test.txt.
Contents of text.txt:
this is a test file
with some contents in it
for testing
file IO

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top