The move operation is more flexible than the copy operation. Copying only works with folders, and you can’t copy between repositories. The move operation, however, works with files and folders within or between repositories.
To move a folder, use the
moveFolder(long folderId, long parentFolderId, ServiceContext serviceContext)
For a full description of this method and its parameters, see its
This method is similar to
copyFolder, but it doesn’t let you change the
folder’s name or description, and it can move folders between repositories.
Folder contents are moved with the folder.
The operation for moving a file is almost identical to moving a folder. To move
a file, use the
moveFileEntry(long fileEntryId, long newFolderId, ServiceContext serviceContext)
For a full description of this method and its parameters, see its Javadoc.
Follow these steps to use
moveFileEntry to move a folder and
a file, respectively. Although this example does both just to demonstrate the
Get a reference to
@Reference private DLAppService _dlAppService;
For more information on this, see the section on getting a service reference in the getting started tutorial.
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
ParamUtil, 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
moveFolderto move a folder (
folderId) to a different folder (
newFolderId). It then calls
moveFileEntryto move a file (
fileEntryId) to the same destination folder:
_dlAppService.moveFolder(folderId, newFolderId, serviceContext); _dlAppService.moveFileEntry(fileEntryId, newFolderId, serviceContext);