Creating Folders

To create folders (Folder entities) in the Documents and Media library, you must use the DLAppService interface’s addFolder method. The steps here show you how to do this. For more detailed information, see Creating Files, Folders, and Shortcuts. For general information on using the API, see Documents and Media API.

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

  1. Get a reference to DLAppService:

    @Reference
    private DLAppService _dlAppService;
    
  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);
    
  1. Call the service reference’s addFolder method with the data from the previous step:

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

    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.

Updating Folders

Deleting Folders

Copying Folders

Moving Folders and Files

« Creating FilesCreating File Shortcuts »
¿Fue útil este artículo?
Usuarios a los que les pareció útil: 0 de 0