• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

writing to a file using javascript

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic