Creating Folders

To create folders (Folder entities) in the Documents and Media library, you must use the DLAppService interface’s addFolder method:

addFolder(long repositoryId, 
        long parentFolderId, 
        String name, 
        String description, 
        ServiceContext serviceContext)

See this method’s Javadoc for a description of the parameters. Note that the description parameter is optional.

Follow these steps to create a folder with the DLAppService method addFolder:

  1. Get a reference to DLAppService:

    private DLAppService _dlAppService;

    For more information on this, see the section on getting a service reference in the getting started tutorial.

  2. Get the data needed to populate the addFolder method’s arguments. Since it’s common to create a folder with data submitted by the end user, you can extract the data from the request. This example does so via javax.portlet.ActionRequest and ParamUtil:

    long repositoryId = ParamUtil.getLong(actionRequest, "repositoryId");
    long parentFolderId = ParamUtil.getLong(actionRequest, "parentFolderId");
    String name = ParamUtil.getString(actionRequest, "name");
    String description = ParamUtil.getString(actionRequest, "description");
    ServiceContext serviceContext = ServiceContextFactory.getInstance(
                DLFolder.class.getName(), actionRequest);

    For more information on getting repository and folder IDs, see the getting started tutorial’s sections on specifying repositories and folders. For more information on ServiceContext, see the tutorial Understanding ServiceContext.

  3. Call the service reference’s addFolder method with the data from the previous step:

    Folder folder = _dlAppService.addFolder(
                            repositoryId, parentFolderId, name, description, 

    The method returns a Folder object, which this example sets to a variable for later use. Note, however, that you don’t have to do this.

You can find the full code for this example in the updateFolder method of Liferay DXP’s EditFolderMVCActionCommand class. This class uses the Documents and Media API to implement almost all the Folder actions that the Documents and Media app supports. Also note that this updateFolder method, as well as the rest of EditFolderMVCActionCommand, contains additional logic to suit the specific needs of the Documents and Media app.

Folders and External Repositories

By creating a folder that acts as a proxy for an external repository (e.g., SharePoint), you can effectively mount that repository inside a Site’s default repository. When users enter this special folder, they see the external repository. These folders are called mount points. You can create one via the API by setting the Service Context’s mountPoint attribute to true, and then using that Service Context in the addFolder method:

serviceContext.setAttribute("mountPoint", true);

Note that the repositoryId of such a folder indicates the external repository the folder points to—not the repository the folder exists. Also, mount point folders can only exist in the default Site repository.

Updating Folders

Deleting Folders

Copying Folders

Moving Folders and Files

« Creating FilesCreating File Shortcuts »
Was this article helpful?
0 out of 0 found this helpful