0

On a SharePoint 2013 document library I have the following JavaScript function attached to the onclick event for each file:

function logAccess(fp) {
   var userID = dsource.user.userid.substring(7);
   var userName = dsource.user.userName;
   var fPath = '\\\\server\\folder\\subfolder\\subfolder2\\subfolder3\\subfolder4\\subfolder5\\';
   var fso = new ActiveXObject('Scripting.FileSystemObject');

   if (fso.FolderExists(fPath)) {
      var s = fso.CreateTextFile(fPath + tStamp + '.txt');
      s.writeline(userID + '|' + userName + '|' + fp);
      s.Close();    
   }
}

This creates a .txt file that tells me who accessed which file when, and saves it to a network drive location (fPath).

It works as expected on Internet Explorer, but since it uses ActiveX it doesn't work on Chrome and I don't have the option to enable IE Tab extension for Chrome.

I've tried using the filesaver.js API and it gets as far as creating a .txt file and downloading it, but it downloads to the user's default download folder (I can't specify a save location path). See below:

function logAccessChr(fp) {
    var userID = dsource.user.userid.substring(7);
    var userName = dsource.user.userName;
    var content = userID + '|' + userName + '|' + fp;
    var filename = tStamp + '.txt';
    var blob = new Blob([content], {
            type: "text/plain;charset=utf-8"
    });
    saveAs(blob, filename);
}

Can anyone think of a different approach to accomplish this on Chrome? Any suggestion is welcome.

edacoding
  • 1
  • 1
  • No other browser is going to be able to do it. – Pointy Oct 22 '19 at 21:43
  • Hi @Pointy , I got to that conclusion too but I was hoping for an alternative solution...Something like storing the logAccess script in a separate location (in SharePoint maybe) and using the onclick event script to call it... Or anything that wouldn't depend on the browser. – edacoding Oct 23 '19 at 15:05

1 Answers1

0

Its not possible because this is a very big security risk. People use real information for their folder structure and accessing the folder names poses an immediate risk. Also, take a look here:

Get browser download path with javascript

Sorry, but it can't be done, for good (security) reasons.

JohnnyAwesome
  • 500
  • 3
  • 10
  • Thank you for your anwer, @JohnnyAwesome. To clarify, I already know the default download path for all users (C:\Users\*UserID*\Downloads) since browser settings are managed by my company. With that said, I'm not trying to access any files within the user's machine, the script itself creates a new file and saves it to a network drive. **My question really is what would be an alternative way to acomplish that. There's also no security concerns since this is an internal SharePoint site with restricted access.** – edacoding Oct 23 '19 at 15:13