To delete a file shortcut with the Documents and Media API, you must use the
deleteFileShortcut
method 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 file shortcut:
-
Get a reference to
DLAppService
:@Reference private DLAppService _dlAppService;
-
Get the file shortcut’s ID. Since it’s common to delete a file shortcut specified by the end user, you can extract its ID from the request. This example does so via
javax.portlet.ActionRequest
andParamUtil
, but you can do this any way you wish:long fileShortcutId = ParamUtil.getLong(actionRequest, "fileShortcutId");
-
Use the service reference to call the
deleteFileShortcut
method with the file shortcut ID from the previous step:_dlAppService.deleteFileShortcut(fileShortcutId);
You can find the full code for this example in the deleteFileShortcut
method
of Liferay DXP’s
EditFileShortcutMVCActionCommand
class. This class uses the Documents and Media API to implement almost all the
FileShortcut
actions that the Documents and Media app supports. Also note that
this deleteFileShortcut
method, as well as the rest of
EditFileShortcutMVCActionCommand
, contains additional logic to suit the
specific needs of the Documents and Media app.