File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes writing to a file using javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "writing to a file using javascript" Watch "writing to a file using javascript" New topic
Author

writing to a file using javascript

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
t this and see if it helps

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

Eric
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
Is the folder shared so it has access to read and write?
[ June 15, 2004: Message edited by: Eric Pascarello ]
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 413
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: writing to a file using javascript
 
Similar Threads
not able to get uploaded file size in javascript
alert box contents as XML
Problem while accessing USERPROFILE folder through JavaScript
Saftey settings on this computer prohibit accessing a data source on another domain
Upload file with checking of size on the client side