We will use an ActiveX Object from the Scripting.FileSystemObject library to read and write files from JavaScript, which knows how to handle files. The parameter of the OpenTextFile function can be (read = 1, write = 2, append = 8).And here are the scripts:

crm2011

1. Reading a file

function ReadFile()
{

var FileOpener = new ActiveXObject(“Scripting.FileSystemObject”);
var FilePointer = FileOpener.OpenTextFile(“C:Zeeshan.txt”, 1, true);
FileContents = FilePointer.ReadAll(); // we can use FilePointer.ReadAll() to read all the lines
alert(FileContents);
FilePointer.Close();
}

2. Writing a file

function WriteFile
{

var FileOpener = new ActiveXObject(“Scripting.FileSystemObject”);
var FilePointer = FileOpener.OpenTextFile(“C:Zeeshan.txt”, 8, true);
FilePointer.WriteLine(“I m a good boy”);
FilePointer.Close();
}

Note:

Go to Tools >> Internet Options >> Security, add page to Trusted sites >> then go to Custom level… and look for Initialize and script ActiveX controls. Enable it and restart the Internet Explorer.

 

Avatar for Joe D365

Joe D365

Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.