Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

writing to a file using javascript

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to write to a file but the execution gets stuck here
var fso = new ActiveXObject('Scripting.FileSystemObject');

DO you have any idea? Is there any other way one can write/append to a file.


function WriteToFile() {

alert('enter writetofile')
var filename = 'c:/sharadatemp.txt';
alert('enter writetofile 1')
var fso = new ActiveXObject('Scripting.FileSystemObject');
alert('enter writetofile 2')
if (fso.FileExists(filename)) {
alert('file already exists')
var a, ForAppending, file;
ForAppending = 8;
file = fso.OpenTextFile(filename, ForAppending, false);
file.WriteLine('Hello Sharada');
file.WriteLine('how are you');
}
else {
alert('create writetofile')
var file = fso.CreateTextFile(filename, true);
file.WriteLine('created file');
file.WriteLine('will write');
}
file.Close();
}

</script>
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
t this and see if it helps

http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20837002.html

Eric
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got the code from site. I tried to save the file as .hta but then it prompts me OPEN SAVE DIALOG BOX...WHICH SHOULD NOT COME UP IN REAL TIME.

Also, It gives me a permision denied message. Right now I am opening/writing the file in my local drive. Is there any other way I can write/append the file.

Any help appreciated.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the folder shared so it has access to read and write?
[ June 15, 2004: Message edited by: Eric Pascarello ]
 
Yuriy Fuksenko
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In IE you could use "Save as" - basically, you define a hidden iframe write content into it and call document.execCommand('SaveAs') on that iframe.

Here is a link on how to do that
http://www.faqts.com/knowledge_base/view.phtml/aid/5785/fid/53
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic