Search code examples
javascriptasp.nethttpactivex

Replacement for ActiveXObject("Scripting.FileSystemObject");


Refactoring old javascript code, what is an effective replacement for the below ActiveX code? Just having the ability to write a local file.

function WriteToFile(bufObj, fileName) {
 var fileObj;
 fileObj = new ActiveXObject("Scripting.FileSystemObject");
 fileObj = fileObj.OpenTextFile(fileName, ForWriting, true, TristateMixed);
 fileObj.Write(bufObj);
 fileObj.Close();
}

Solution

  • You don't have that ability in a modern browser. (unless someone is crazy enough to still allow ActiveX controls - which no one does anymore).

    the local file system is 100% HANDS off!!!

    If you allow this?

    Then when you come to my site to look at a cute cat picture? Then I am going to rummage around - and up-load say a text file called "my passwords". Or how about I go rummage around and look for a file called my banking?

    or grab all your emails?

    In fact, your JavaScript cannot even SELECT or set a file when using the file-up-load. So, any kind of local file access is not allowed, and is out of the question.

    If this was to be allowed, then no one would ever use nor trust the internet again!

    It is a security hole far to large. Now perhaps this might be some internal "only" web site, and some kind of local file rights and access is to be allowed? That being the case? You have to continue to allow and setup the browser to allow ActiveX for that internal site - but this is a high risk adventure.

    So, you don't have a replacement, since browsers are locked down from code even touching, knowing or having ANY knowledge of the client side folders. Beside, the user might be on their Android phone, or a iPad - and they have rather different file systems anyway (and they don't have support for ActiveX either).

    So, modern browsers have ZERO ability, I repeat ZERO ability to see, touch, know about the existence of ANY local file - it simple not allowed. About the only way around this issue would be to find a browser that still supports and allows ActiveX - and they are far and few between these days.