1

I am using the following piece of code and it works perfectly fine when used locally, but can it be used for server purposes??

function WriteToFile(data) {
    var currentdate = new Date(); 
    var datetime = "Time: " + currentdate.getDate() + "/" + (currentdate.getMonth()+1)  + "/" + currentdate.getFullYear() + " @ " + currentdate.getHours() + ":" + currentdate.getMinutes() + ":" + currentdate.getSeconds();
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var a = fso.OpenTextFile("C:\\logs\\log.txt", 8);
    a.WriteLine(datetime);
    a.WriteLine(data + "\n");
    a.Close();
 }

I've tried everything for the path to the txt file in my Z: drive with no luck whatsoever. Is this even possible? I've also granted access to "Everyone" to the folder so it can be readable and writeable but still I cannot open the txt file to edit it. For the record I am using IE8.

Any suggestions?

randomizertech
  • 2,309
  • 15
  • 48
  • 85

1 Answers1

1

You cannot access any of the files on the server with the ActiveX Scripting.FileSystemObject using the syntax in your example. This is since the ActiveX FileSystemObject control will be executed on the client side because there's no remote server specified and therefore it only has access to the client's file system. You could specify a remote server using your syntax, but it's not supported in IE 9 standards mode, or IE 10 and above, so it's not really recommended.

Instead, to access the server's file system you will need to create a FileSystemObject on the server side using a server-side language such as Active Server Pages (ASP). In ASP FileSystemObject it would be instantiated using Server.CreateObject("Scripting.FileSystemObject")

Some good examples for using FileSystemObject with ASP can be found here: http://support.microsoft.com/kb/218606 and here:http://www.codeproject.com/Articles/7296/Reading-Files-in-ASP-and-How-to-Search-for-a-parti

KernelPanik
  • 8,169
  • 1
  • 16
  • 14