cancel
Showing results for 
Search instead for 
Did you mean: 

How to get full folder path from noderef

vince20151
Champ in-the-making
Champ in-the-making
I'm implementing an action when a file (document) is created in a folder. I have access to the noderef of the document.
I like to get the full folder name where the document has just been created. My code has condition logic on how to act based on the folder name.
How do I do this in java?
Thanks a bunch!
6 REPLIES 6

iv0id
Champ in-the-making
Champ in-the-making
You can use something like :


Document doc = (Document) session.getObject(object_id);
doc.getPaths().get(0);


the name of the document is concatenated at the end of the path so you have to remove it.

vince20151
Champ in-the-making
Champ in-the-making
I'm in java. Not JavaScript so I don't think I can use this.
I have access to the NodeRef and the NodeRefService which I can use but I can't find any reference showing me how to get the Path of the document. I can get the FileInfo object for the document but this FileInfo only seems to contain the file name and whether the noderef is a file or a folder. I need the full path like /Sites/aptest/documentLibrary/DropOff/Invoice1.pdf (not just the file name which is Invoice1.pdf)

kaynezhang
World-Class Innovator
World-Class Innovator
Use NodeService's getPath method ,which will return Path object ,then use Path Object's toString()/toPrefixString()/toDisplayPath() method according your requirements.

muralidharand
Star Contributor
Star Contributor
Hi,
This may help you.

<java>
Path folderPath = nodeService.getPath("FOLDER_NODE_REF");
If you need the folder path as prefixed string,

String prefixedPath = folderPath.toPrefixString(namespaceService);

</java>

varunchawla
Champ in-the-making
Champ in-the-making

what if i want noderef by providing the path of file?
I have file present in alfresco repository at some path. How do i get the noderef using path.
Actually i want to download that on my project.

kaynezhang
World-Class Innovator
World-Class Innovator

Please use following method of org.alfresco.service.cmr.model.FileFolderService,it is used to resolve a file or folder name path from a given root node down to the final node.

for rootNodeRef you can pass company root node
public FileInfo resolveNamePath(NodeRef rootNodeRef, List<String> pathElements) throws FileNotFoundException;