IT Community - Software Programming, Web Development and Technical Support

How do I write a file from JavaScript?

This is a discussion on How do I write a file from JavaScript? within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; Hi all...... How do I write a file from JavaScript? Thanks & Regards itbarota....


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > HTML, CSS and Javascript Coding Techniques

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 09-13-2007, 03:22 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default How do I write a file from JavaScript?

Hi all......

How do I write a file from JavaScript?

Thanks & Regards
itbarota.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-13-2007, 04:27 AM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default Re: How do I write a file from JavaScript?

Hi all....

Writing a file from JavaScript is just as easy as writing a file from a Java applet. Your script cannot write files itself; it should call a Java applet's public method which will actually do all the dirty file writing work for you.

The bad news is that

1. Writing is a privileged operation, and therefore your Java applet must be digitally signed in order to write files.
2. Applet signing for Internet Explorer is completely different from applet signing for Netscape Navigator.
3. Signed applets may not work properly in Netscape Navigator 3.
4. What's the worst, it's very insecure to put privileged operations in public methods of signed applets! If you publsh such an applet, a malicious code could easily subvert the applet's public methods, and you (the applet publisher/signer) will be sued for any damage!

Therefore, nobody publishes scripts that write files via signed applets, although in versions 4 of both major browsers it's technically possible.

Thanks.....
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-20-2007, 10:44 PM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 138
GDevakii is on a distinguished road
Default Re: How do I write a file from JavaScript?

function WriteToFile() {
try {
var fso, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
s = fso.CreateFolder("C:\\test.txt", true);
s.writeline("This is a test");
s.Close();
}
catch(err){
var strErr = 'Error:';
strErr += '\nNumber:' + err.number;
strErr += '\nDescription:' + err.description;
document.write(strErr);
}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-26-2007, 04:38 AM
varghese varghese is offline
D-Web Programmer
 
Join Date: Feb 2007
Posts: 93
varghese is on a distinguished road
Thumbs up Re: How do I write a file from JavaScript?

hi GDevakii,
i tryed your code but i got the error "ActiveXObject is not defined";
how to solve this?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 10-26-2007, 01:52 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Smile Re: How do I write a file from JavaScript?

function WriteToFile(sText)
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var FileObject = fso.OpenTextFile("C:\\LogFile.txt", 8, true,0); // 8=append, true=create if not exist, 0 = ASCII
FileObject.write(sText)
FileObject.close()
}
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 10-26-2007, 01:54 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Smile Re: How do I write a file from JavaScript?

function WriteToFile(sText)
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var FileObject = fso.OpenTextFile("C:\\LogFile.txt", 8, true,0);
true=create if not exist, 0 = ASCII
FileObject.write(sText)
FileObject.close()
}
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
JavaScript to include flash file in asp.net kingmaker ASP and ASP.NET Programming 3 03-10-2008 03:20 AM
How do I write a clock program in JavaScript? itbarota HTML, CSS and Javascript Coding Techniques 2 10-12-2007 10:55 PM
How can I write Arabic characters in my Javascript? Pvinothkumar HTML, CSS and Javascript Coding Techniques 1 09-14-2007 12:44 AM
How to Read and write txt file using C# kingmaker C# Programming 2 08-25-2007 02:40 AM
What’s the difference between Response.Write() andResponse.Output.Write()? prasath ASP and ASP.NET Programming 1 07-19-2007 03:56 AM


All times are GMT -7. The time now is 01:12 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0