How to get the path of Shared Files with JavaScript

cancel
Showing results for 
Search instead for 
Did you mean: 
zputnoky
Established Member

How to get the path of Shared Files with JavaScript

Jump to solution

Is there a way to get the path of the Shared Files with JavaScript? like using roothome? or similar? I need to be able to create a file in the shared files folder from a JavaScript.

Thanks alot,

Zsolt Putnoky

1 Solution

Accepted Solutions
afaust
Master

Re: How to get the path of Shared Files with JavaScript

Jump to solution

First of all, which level of JavaScript are you referring to? Since you mention "roothome" as a similar root object, I assume you mean Repository-tier, server-side JavaScript. But in the past a lot of people have confused this also with Share-tier, server-side JavaScript or even Share-tier, client-side JavaScript, so I just want to make sure...

In JavaScript there is no special object / constant by default to refer to the Shared Files directory. You always have to look it up by path from either "roothome" or "companyhome". Beware though that the name of the folder is dependent on the locale of the server during installation, e.g. it may change from system to system. So as an addon developer you should never rely on any particular name - only as a customer who develops for a single system should you "hardcode" the name/path into JavaScript files.

One reasonable stable option is to resolve the folder by XPath. Though technically the XPath fragment could also be reconfigured via alfresco-global.properties before the iniital bootstrap of Alfresco, very few (if any) people actually do that and chances are that doing so would break core Alfresco features (Alfresco themselves are prone to sometimes hardcoding their default paths into new functionality). Using the default path fragment you should be able to lookup the shared files folder like this:

var sharedFolderCandidates, sharedFolder;
sharedFolderCandidates = companyhome.childrenByXPath('app:shared');

if (sharedFolderCandidates.length !== 1)
{
   throw new Error('Inconclusive lookup result for Shared Files folder');
}
sharedFolder = sharedFolderCandidates[0];

// do stuff‍‍‍‍‍‍‍‍‍‍

View solution in original post

2 Replies
afaust
Master

Re: How to get the path of Shared Files with JavaScript

Jump to solution

First of all, which level of JavaScript are you referring to? Since you mention "roothome" as a similar root object, I assume you mean Repository-tier, server-side JavaScript. But in the past a lot of people have confused this also with Share-tier, server-side JavaScript or even Share-tier, client-side JavaScript, so I just want to make sure...

In JavaScript there is no special object / constant by default to refer to the Shared Files directory. You always have to look it up by path from either "roothome" or "companyhome". Beware though that the name of the folder is dependent on the locale of the server during installation, e.g. it may change from system to system. So as an addon developer you should never rely on any particular name - only as a customer who develops for a single system should you "hardcode" the name/path into JavaScript files.

One reasonable stable option is to resolve the folder by XPath. Though technically the XPath fragment could also be reconfigured via alfresco-global.properties before the iniital bootstrap of Alfresco, very few (if any) people actually do that and chances are that doing so would break core Alfresco features (Alfresco themselves are prone to sometimes hardcoding their default paths into new functionality). Using the default path fragment you should be able to lookup the shared files folder like this:

var sharedFolderCandidates, sharedFolder;
sharedFolderCandidates = companyhome.childrenByXPath('app:shared');

if (sharedFolderCandidates.length !== 1)
{
   throw new Error('Inconclusive lookup result for Shared Files folder');
}
sharedFolder = sharedFolderCandidates[0];

// do stuff‍‍‍‍‍‍‍‍‍‍
zputnoky
Established Member

Re: How to get the path of Shared Files with JavaScript

Jump to solution

Hi Axel,

I was looking for the solution you described and after plenty of search found somewhere buried deep in a doc. Managet to get the content of the shared files node listed by a JavaScript program.

Thanks alot for your help,

Best regards,

Zsolt Putnoky