Deleting File Versions

To delete a file version with the Documents and Media API, you must use the deleteFileVersion 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 use deleteFileVersion to delete a file version:

  1. Get a reference to DLAppService:

    @Reference
    private DLAppService _dlAppService;
    
  2. Get the file entry ID and version for the file you want to delete. Since it’s common to delete a file version specified by the end user, you can extract these parameters from the request. This example does so via javax.portlet.ActionRequest and ParamUtil, but you can do this any way you wish:

    long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId");
    String version = ParamUtil.getString(actionRequest, "version");
    
  3. Use the service reference to call the deleteFileVersion method with the file entry ID and version from the previous step:

    _dlAppService.deleteFileVersion(fileEntryId, version);
    

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

Deleting Files

Deleting File Shortcuts

Deleting Folders

Moving Entities to the Recycle Bin

« Deleting FilesDeleting File Shortcuts »
Was this article helpful?
0 out of 0 found this helpful