• flickr
  • linkedin
  • twitter
  • rss
Write to local drive with javascript – hta

Write to local drive with javascript – hta

This will create a text file ‘text.txt’ in the folder where test.hta is residing. Could use to create xml and config files with javascript for courses to manipulate later.

<html>
<head>
<script language="javascript">

function WriteToFile() {
 try {
   var fso, s;
   fso = new ActiveXObject("Scripting.FileSystemObject");
   /* s = fso.OpenTextFile("C:\\test.txt" , 8, 1, -2); */
   s = fso.OpenTextFile("test.txt" , 8, 1, -2);
   s.writeline("This is a test");
   s.Close();
 }
catch(err){
  var strErr = 'Error:';
  strErr += '\nNumber:' + err.number;
  strErr += '\nDescription:' + err.description;
  document.write(strErr);
 }
}

WriteToFile();

</script>
</head>
<body>

</body>
</html>

Source: http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20837002.html

Tech Reference:

Larry's a 30-something chap interested in travel, being a dork and changing the world via less boring training.

Leave a reply