Moving Folders and Files

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:

  1. Get a reference to DLAppService:

        private DLAppService _dlAppService;
  2. 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 and 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);
  1. Call the service reference’s method(s). This example calls moveFolder to move a folder (folderId) to a different folder (newFolderId). It then calls moveFileEntry to move a file (fileEntryId) to the same destination folder:

    _dlAppService.moveFolder(folderId, newFolderId, serviceContext);
    _dlAppService.moveFileEntry(fileEntryId, newFolderId, serviceContext);

Copying Folders

« Copying FoldersGetting Entities »
Was this article helpful?
0 out of 0 found this helpful