activex - Javascript: how to append data to a file - Stack Overflow

how can i append data to a file using javascript?i tried to use this code, but i got an error:var fso =

how can i append data to a file using javascript?

i tried to use this code, but i got an error:

var fso = new ActiveXObject("Scripting.FileSystemOject");
var filepath = fso.GetFile("member.txt");
var fileObject = fso.OpenTextFile(filepath, 8);
file.WriteLine(id + "|" + pass);
fileObject.close();

the error is on var fso = new ActiveXObject("Scripting.FileSystemOject");, written: Error: Automation server can't create object

is there any other way to append the file using javascript or the way to fix this? thanks :)

EDIT: i have doing what's written on this, and it still not working :/

how can i append data to a file using javascript?

i tried to use this code, but i got an error:

var fso = new ActiveXObject("Scripting.FileSystemOject");
var filepath = fso.GetFile("member.txt");
var fileObject = fso.OpenTextFile(filepath, 8);
file.WriteLine(id + "|" + pass);
fileObject.close();

the error is on var fso = new ActiveXObject("Scripting.FileSystemOject");, written: Error: Automation server can't create object

is there any other way to append the file using javascript or the way to fix this? thanks :)

EDIT: i have doing what's written on this, and it still not working :/

Share Improve this question edited Apr 17, 2012 at 15:14 aquatorrent asked Apr 17, 2012 at 14:49 aquatorrentaquatorrent 8412 gold badges8 silver badges11 bronze badges 7
  • Make sure you have scrrun.dll installed and registered into your OS. A quicktest: write to mandline: scrrun.dll. If you'll get a WINDOWS error, the dll exists, if error text occurs only in manline, there is not scrrun.dll installed/registered. You can also try to find the file from system32-folder – Teemu Commented Apr 17, 2012 at 16:28
  • i've run it and it gives me a warning that i wanted to open the file :/ – aquatorrent Commented Apr 17, 2012 at 16:31
  • Well, the installation seems to be OK then... And you've switched all the necessary settings to "insecure" mode? – Teemu Commented Apr 17, 2012 at 16:38
  • how can i switch it to insecure mode? – aquatorrent Commented Apr 17, 2012 at 16:39
  • 1 I just realized after wasting an hour, the OP misspelled "Scripting.FileSystemOject", there's 'b' missing in object. That's why it's giving out that error (even if you apply the fix.) Don't copy it into your code :) – c00000fd Commented May 4, 2014 at 22:58
 |  Show 2 more ments

4 Answers 4

Reset to default 1

I just realized these in your code:

var fileObject = fso.OpenTextFile(filepath, 8,true);

You'll need the true-argument, if the file does not exist, or you want to overwrite/append it.

var filepath = fso.GetFile("member.txt");// This won't work.
var filepath = "your_filePath"; // Use this instead
var fileObject = fso.OpenTextFile(filepath, 8, true);

OpenTextFile() needs a path as a string like "D:/test/file.txt". GetFile() returns an object, which you can see as a string (D:\test\file.txt), but it's not a string. Use also absolute paths, relative paths don't seem to work by my experience.

EDIT

Add the code below to the <head>-part of your html-file, then save locally as a hta (with file extension hta, not htm or html).

<hta:application
  applicationName="MyApp"
  id="myapp"
  singleInstance="yes"
/>

Then run the hta-file. If you still getting an ActiveX-error, it's not supported by your OS. If this works, you haven't done all the security settings correct.

EDIT II

In this case it's not very usefull to get the path through ActiveX, you'll need to write it literal anyway. And I'm not supposed to do your homeworks, but this does the trick...

var filepath = new String(fso.GetFile("member.txt")).replace(/\\/g,'/');

And don't forget what I've said above about using absolute paths...

The 8 in the OpenTextFile function specify that you want to append to the file. Your problem es from the security restriction of your browser. To make it work you'll have to lower the security level, which is not really remended.

The error is thrown because there are security restrictions which donot allow the activex to run. change your security settings to allow the activex if your using internet explorer (which i think you are). This might be useful http://windows.microsoft./en-US/windows/help/genuine/ie-activex Cheers

EDIT: i have doing what's written on this, and it still not working :/ * try Restarting your browser

As pointed out in this ment

Javascript: how to append data to a file

the cause of the error Error: Automation server can't create object is the typo in the progid passed to ActiveXObject: Oject instead of Object:

var fso = new ActiveXObject("Scripting.FileSystemOject");

there is a missing b!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745395405a4625854.html

相关推荐

  • activex - Javascript: how to append data to a file - Stack Overflow

    how can i append data to a file using javascript?i tried to use this code, but i got an error:var fso =

    8小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信