To delete a folder with the Documents and Media API, you must use one of the two
deleteFolder
methods discussed in
Deleting Entities.
The steps here show you how. For general information on using the API, see
Documents and Media API.
Follow these steps to delete a folder:
-
Get a reference to
DLAppService
:@Reference private DLAppService _dlAppService;
-
Get the data needed to populate the arguments of the
deleteFolder
method you wish to use. Since it’s common to delete a folder specified by the end user, you can extract the data you need from the request. This example does so viajavax.portlet.ActionRequest
andParamUtil
, but you can get the data any way you wish. Also note that this example gets only the folder ID because the next step deletes the folder withdeleteFolder(folderId)
:long folderId = ParamUtil.getLong(actionRequest, "folderId");
If you want to use the other
deleteFolder
method, you can also get the repository ID, parent folder ID, and folder name from the request. -
Call the service reference’s
deleteFolder
method you wish to use with the data from the previous step. This example callsdeleteFolder
with the folder’s ID:_dlAppService.deleteFolder(folderId);
You can find the full code for this example in the deleteFolders
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
deleteFolders
method, as well as the rest of EditFolderMVCActionCommand
,
contains additional logic to suit the specific needs of the Documents and Media
app.