cancel
Showing results for 
Search instead for 
Did you mean: 

create folder

enkidu
Champ in-the-making
Champ in-the-making
hi mates,

how do i create a folder with filefolderservice? i wanna create a folder in the documentlibrary lets say i.e.: 2013-003 any ideas?

found this below.. but this is only for creating files but i need a folder in a specific folder



       QName contentQName = QName.createQName("{http://www.alfresco.org/model/content/1.0}content");
       FileInfo pdfInfo = fileFolderService.create(directory, filename, contentQName);
       NodeRef pdf = pdfInfo.getNodeRef();


7 REPLIES 7

mitpatoliya
Star Collaborator
Star Collaborator
If above code is working for you then to create folder you just need to change this line
QName contentQName = QName.createQName("{http://www.alfresco.org/model/content/1.0}content");
with

this one
QName contentQName = QName.createQName("{http://www.alfresco.org/model/content/1.0}folder");

enkidu
Champ in-the-making
Champ in-the-making
thnx for ur reply.. can u tell me what directory (FileInfo pdfInfo = fileFolderService.create(directory???, filename, contentQName);
) should look like??

mitpatoliya
Star Collaborator
Star Collaborator
directory is nothing but the noderef of parent space under which you want to create folder.
you have to get it from repo using search,

kaynezhang
World-Class Innovator
World-Class Innovator

You can first search parent directory by using  FileFolderService.searchSimple() or FileFolderService.search() method and then use create() method to create a file or folder; or any type derived from file or folder.

enkidu
Champ in-the-making
Champ in-the-making
hi mate.. i need an example.. some code snippets would be great..

kaynezhang
World-Class Innovator
World-Class Innovator
Get root node using nodeService

        NodeRef storeRootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);

Search parent directory ith the matching name pattern using fileFolderService or using searchServcie

   //using fileFolderService
        List<FileInfo> parentDirectory = fileFolderService.searchstoreRootNodeRef , "folder name****", true);
   NodeRef parentNodeRef = parentDirectory .getNodeRef();
   //using searchService
        List<NodeRef> results = searchService.selectNodes(
                storeRootNodeRef,
                "/app:company_home/app:****/",
                null,
                namespaceService,
                false,
                SearchService.LANGUAGE_XPATH);
        if (results.size() == 0)
        {
            throw new AlfrescoRuntimeException("Didn't find node"+name);
        }
        NodeRef parentNodeRef = results.get(0);

Create a file or folder

   FileInfo object = fileFolderService.create(parentNodeRef, "name", TYPE_CONTENT);

enkidu
Champ in-the-making
Champ in-the-making
hi mate.. thnx a lot for ur help.. for all have the same problem solution can be found here: https://forums.alfresco.com/forum/developer-discussions/repository-services/urgent-query-string-1203...