To move folders and files with the Documents and Media API, use the moveFolder
and moveFileEntry
methods discussed in
Copying and Moving Entities.
The steps here show you how. For general information on using the API, see
Documents and Media API.
Follow these steps to use moveFolder
and moveFileEntry
to move a folder and
a file, respectively. This example does both to demonstrate the procedures:
-
Get a reference to
DLAppService
:@Reference private DLAppService _dlAppService;
-
Get the data needed to populate the method arguments. Since moving folders and files is typically done in response to a user action, you can get the data from the request. This example does so via
javax.portlet.ActionRequest
andParamUtil
, but you can get the data any way you wish:// Get the folder IDs long folderId = ParamUtil.getLong(actionRequest, "folderId"); long newFolderId = ParamUtil.getLong(actionRequest, "newFolderId"); // Get the file ID long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId"); ServiceContext serviceContext = ServiceContextFactory.getInstance( DLFileEntry.class.getName(), actionRequest);
-
Call the service reference’s method(s). This example calls
moveFolder
to move a folder (folderId
) to a different folder (newFolderId
). It then callsmoveFileEntry
to move a file (fileEntryId
) to the same destination folder:_dlAppService.moveFolder(folderId, newFolderId, serviceContext); _dlAppService.moveFileEntry(fileEntryId, newFolderId, serviceContext);