Copy a folder in Alfresco

642 Views Asked by At

I want to copy a folder into another, in Alfresco, recursively, with Java.

I only have the NodeRef of each folder.

How to do?

2

There are 2 best solutions below

2
On

Just in case anybody is looking for copying file(s) from to destination folder in alfresco:

String docName = nodeService.getProperty(fileNode, ContentModel.PROP_NAME).toString();
QName documentName = QName.createQName(CustomModel.CUSTOM_NAMESPACE_URI,docName);
NodeRef copiedFile = copyService.copy(fileNode, destnode, ContentModel.ASSOC_CONTAINS, documentName);

nodeService.setProperty(copiedFile, ContentModel.PROP_NAME, docName); 

The last line sets the copied file name to actual document name; else you will find the copied file name as noderef of the file

0
On

Use CopyService.copyAndRename:

copyService.copyAndRename(
    sourceNodeRef,
    destinationNodeRef,
    ContentModel.ASSOC_CONTAINS,
    QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "New name"),
    true // Recursive
);

Inspired from Alfresco's own ScriptNode.java.