ReferenceError: not defined with activeX - javascript

what does it mean to get this error:
ReferenceError: ActiveXObject is not defined
var fso = new ActiveXObject("Scripting.FileSystemObject");
here is my code:
var fso = new ActiveXObject("Scripting.FileSystemObject");
varFileObject = fso.OpenTextFile("C:\\LogFile.txt", 8, true,0); // 8=append, true=create if not exist, 0 = ASCII
newObject.write(XML.innerHTML);
newFileObject.close();
thanks in advance..

The problem is the security setting of your browser is blocking it.
If you try IE6 the code should work. You have to use a dead browser because the new browsers block it from working as part of a killbit fix that Microsoft did to fix a security issue.

Related

Can I create a folder using Javascript program

Can I create a folder using Java script program like
var fso, fldr;
fso = new ActiveXObject("Scripting.FileSystemObject");
fldr = fso.CreateFolder("C:\\MyTest");
ActiveXObject is only available within Internet Explorer, also the correct permissions must be set before this is possible.
More info:
http://www.ezineasp.net/post/Javascript-FSO-CreateFolder-Method.aspx
Yes you can create, however it will only run IE browser and you need to perform IE - setting too.
var folder = "C:\\testing";
var fso = new ActiveXObject("Scripting.FileSystemObject");
if (!fso.FolderExists(folder)) {
fso.CreateFolder(folder);
}
fso=null;
It's not possible with other Browsers! And that's good!

ActiveXObject FileSystemObject not releasing in Javascript

I have a Javascript function that saves JSON data locally, using an ActiveXObject in IE9. It links into FileSystemObject or FSO scripting for file access.
If this Javascript function is run more than once, I get an error in IE debugger: "SCRIPT70: Permission denied" pointing to ts = savefile.OpenAsTextStream(2);
Why will it run just fine the first time, but not after that? My best guess is that something's not being released properly, although I can find no information on MSDN (or here).
Here's the code:
function SaveMyJSON() {
var ts;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var savefilepath = "C:\\MyFolder\\saveFile.json"
var savefile = fso.GetFile(savefilepath);
// open for writing only, value 2, overwriting the previous
// contents of the file
ts = savefile.OpenAsTextStream(2);
var myTestJson = {"id1" : "one", "id2" : "two"};
// copy to json
ts.WriteLine(myTestJson);
ts.Close;
}
The Close method needs empty parenthesis after it, like so:
ts.Close();
Ref here for more info.

Javascript: Save file with ActiveXobject

I am working on an Asp .net project and i have a textarea in an aspx page, and i am trying to save textarea contents on a file on the server by clicking a button with the following code:
var fso = new ActiveXObject("Scripting.FileSystemObject");
var a = fso.CreateTextFile("c:\\temp1\\testfile.txt", true);
a.WriteLine(saveData);
a.Close();
The issue is if the file does not exists , then it creates it. But if it exists it dodes not overwrite it. Any help pls ? (I have to mention that Localy runing the application with visual studio then it rewrites it, but it doesnt works on the published version )
Use rather OpenTextFile() than CreateTextFile(). It also creates non-existing file if needed.
var fso = new ActiveXObject("Scripting.FileSystemObject");
var a = fso.OpenTextFile("c:\\temp1\\testfile.txt",2, true);
a.WriteLine(saveData);
a.Close();

javascript or jquery fileSize

I was looking all over the web how i can get the file size on the client side
so i found a few examples
the first example was
$(this)[0].files[0].fileSize
but unfortunately it does not working in ie
so i found this example
function getSize(){
var myFSO = new ActiveXObject("Scripting.FileSystemObject");
var filepath = document.upload.file.value;
var thefile = myFSO.getFile(filepath);
var size = thefile.size;
alert(size + " bytes");
}
which is suppose to work in ie but i heard it has security problems and i don't know if it work in all browsers..
so , i need to know what i can use in javascript client side to get the file size..
e.g : file from input type file
thank you for helping.
JavaScript cannot access any information about local files. This is done deliberately for security reasons.
ActiveXObject("Scripting.FileSystemObject"); is an IE-only construct and will not work across browsers.

How to define ActiveXObject in selenium.geEval method?

i'm using selenium rc for automation i used selenium.GetEval(" var fso = new ActiveXObject('Scripting.FileSystemObject')"); but it shows activex not defined error during run time..
selenium.GetEval(" var fso = new ActiveXObject('Scripting.FileSystemObject')"); it will work only IE not in FireFox.

Categories

Resources