Updating Folders

To update a folder with the Documents and Media API, you must use the updateFolder method discussed in Updating Entities. The steps here show you how. For general information on using the API, see Documents and Media API.

Follow these steps to update a folder:

  1. Get a reference to DLAppService:

    private DLAppService _dlAppService;
  2. Get the data needed to populate the updateFolder method’s arguments. Since it’s common to update 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, but you can get the data any way you wish:

    long folderId = ParamUtil.getLong(actionRequest, "folderId");
    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 updateFolder method with the data from the previous step:

    _dlAppService.updateFolder(folderId, name, description, serviceContext);

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.

Creating Folders

Deleting Folders

Copying Folders

Moving Folders and Files

« Updating FilesUpdating File Shortcuts »
Was this article helpful?
0 out of 0 found this helpful