javascript >> javascript with wscript filesystemobject

by pantagruel » Tue, 01 Aug 2006 19:11:35 GMT

Hi, I'm trying to write to a file.

The file is getting created.

The file is even getting written to because the file ends up being one
kb. so I guess there is something coming in.

The code that is driving me crazy right now is:

xslt2.stylesheet = xslDoc2;
xslProc2 = xslt2.createProcessor();
xslProc2.input = xmlDoc;

openfile = fso.GetFile(newFileObject);
openedfile = openfile.OpenAsTextStream(2, true);


The XSLT above is being loaded. the transform executed, the output

But when I try to write that output to the file it does not work. note
the file is getting created and it exists.


javascript >> javascript with wscript filesystemobject

by Martin Honnen » Tue, 01 Aug 2006 20:25:18 GMT

That parameter should be -1 for Unicode (UTF-16), 0 for ASCII, -2 for
the Windows default code page (e.g. Windows-1252).

What kind of transformation result are you trying to create? If you want
to create an XML document as the result of the transformation then it is
much easier to do e.g.
// you need to adapt the version number so it is consistent
// with the other objects you use above
var resultDocument = new ActiveXObject('Msxml2.DOMDocument.3.0');
xslProc2.output = resultDocument;


Martin Honnen

javascript >> javascript with wscript filesystemobject

by pantagruel » Wed, 02 Aug 2006 18:58:43 GMT

Thanks, I ended up:

result = xslProc2.output;


//save error text to file.

openfile= fso.OpenTextFile(newFileObject,8,true);

Needed to do it that way to get a text output.


Similar Threads

1. File copy using javascript not Filesystemobject

2. WScript JavaScript library


I'm thinking of making a WScript based JavaScript library, I can think
of some specific non-browser specific scripting examples that should
probably make it in, like Crockford's little JavaScripter, can anyone
think of anything else. Is anyone familiar with anything similar
already done.

Things that I am thinking that to provide are:

JavaScript helper functions to make WMI queries, manage returned WMI

JavaScript with such technologies as HTA.

Anything that people can think such a  library should specifically

3. Javascript WScript.SendKeys problem with Vista - Internet Explorer/IE

4. Javascript and WScript


I need to use WScript on an intranet based application to retrive client's 
The script is very simple which i have copied below.

<script language=javascript>   
  function getNTUsername(){
var wshNetwork = new ActiveXObject("WScript.Network");   
        alert('domain ='+   wshNetwork.UserDomain);   
        alert('machine name = '+   wshNetwork.ComputerName);   
        alert('user name = '+   wshNetwork.UserName);
        document.getElementById('username').value = wshNetwork.UserName;
        document.getElementById('UsernameDiv').innerHTML = 

I when run the html file it throws error "Automation server cant create 
object."  I can get it working I enable Initialize and script ActiveX control 
not marked as safe.

Is there are way to mark my script as safe or is there any thing or method I 
can use to retrive this information from client browser. We are running an 
apache server.



5. Javascript: WScript Undefined Error - Adobe Dreamweaver

6. Remote filesystemobject (2nd try)

I am a near total novice, trying to write some Javascript code that will
display certain elements in a comma separated value file (gifts.csv) in
tabular form when a page is loaded. I have come up with the following which
works fine when I view the page in my coding tool (AceHTML 5 Pro). Basically
it sets up an array, opens the csv file, reads each line from the file,
decides whether the line needs processing and if so loads each value into an
element of the array and writes some of them out. There are some table tags
thrown into appropriate places.


information = new Array(10);
y = new ActiveXObject("Scripting.FileSystemObject");
gift = y.opentextfile("gifts.csv",1);
x = document.write("<table>");

do {
x = document.write("<tr>");
giftinfo = gift.readline();

if (giftinfo.charAt(0)=="0") {
information = giftinfo.split(",");
x = document.write("<td>",information[4],"</td>");
x = document.write("<td>",information[5],"</td>");
x = document.write("<td>",information[9],"</td>");
x = document.write("</tr>");
while (!gift.AtEndOfStream);

x = document.write("</table>");


However it doesn't work from a server using IE. From what I've read I
believe it is because the filesystemobject works with the local filesystem
whereas the csv file is on the server.

Is there any way of redoing this so that the file on the server is opened
and read, or can I download the csv file onto the client machine so that it
works as written, or do I need to be doing something with asp (is that
right?) so the the scripting runs on the server not the client?

Or am I asking the wrong questions?

7. IE fileSystemObject from JS?

8. FileSystemObject sees unexisting files!

I use FSO ActiveXObject to save file from IE. In JS like

function saveToFile(pathN, content){
	var fso, ts;
	var ForWrite = 2;	
	fso = new ActiveXObject("Scripting.FileSystemObject");
	ts = fso.OpenTextFile(pathN, ForWrite, true);
	if (!fso.FileExists(pathN)) {	
		alert("The file <"+pathN+"> cannot be created.");
	} else {
		alert("Successfully saved");

surprisingly if the pathN contains unexisting path and the file is not
created, the fso.FileExists(pathN) still returns true (the message
"Successfully saved" is written...).

What's wrong there ?