Moving Folders and Files

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 DLAppService method moveFolder:

moveFolder(long folderId, long parentFolderId, ServiceContext serviceContext)

For a full description of this method and its parameters, see its Javadoc. 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 DLAppService method moveFileEntry:

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 moveFolder and moveFileEntry to move a folder and a file, respectively. Although this example does both just to demonstrate the procedure:

  1. Get a reference to DLAppService:

    private DLAppService _dlAppService;

    For more information on this, see the section on getting a service reference in the getting started tutorial.

  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);

    For more information on getting folder IDs, see the getting started tutorial’s section on specifying folders. For more information on ServiceContext, see the tutorial Understanding ServiceContext.

  3. 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 »
Este artigo foi útil?
Utilizadores que acharam útil: 0 de 0