POWEROBJECTS

718 Washington Ave. N. Suite #101
Minneapolis, MN 55401
View map and all Locations

Send us a message

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 JoeCRM

JoeCRM

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