How to read and write textfiles using javascript


How to read and write text files using javascript

Description



You can read and write to a text files using javascript.It is working in IE6 and IE7.Just you need go to tools ->internet options ->Security -> Custom level -> then mark Initialize and script ActiveX controls not marked as safe as Enable.


<script language=javascript>

function WriteToile()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fileOpen = fso.OpenTextFile("c:\\test.txt",2,true); // Open the file for writing
fileOpen.WriteLine("Some Text added");
fileOpen.Close();
}
function ReadTextFile()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fileOpen = fso.OpenTextFile("c:\\test.txt",1,true); // Open the file for writing
var filecontent = fileOpen.ReadLine();
alert(filecontent);
fileOpen.Close();
}
</script>


Note:The “Initialize and Script ActiveX controls not marked as safe” option should be selected as “Enable”.Goto Tool Menu in browser ->Internet Option ->Security -> select Local intranet -> Click Custom Level ->go to "Initialize and Script ActiveX controls not marked as safe" and mark as enable

Thanks


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: