SAP KM API – Copy KM Folders
Below code snip can be used to copy one KM folder and its subfolders to another location.
Note:
1. The destination folder shouldn’t exist before the copy. Otherwise the copy method will raise an exception.
2. The source folder display name are copied too. It might need to be changed if necessary.
String source = ";/documents/source";; String destination = ";/documents/destination";; try { //1. Create a RID RID aRid = RID.getRID(source); logger.errorT(aRid.getPath()); //2. Get Resource Factory IResourceFactory resourceFactory = ResourceFactory.getInstance(); //3. Get user and resource context com.sapportals.portal.security.usermanagement.IUser user = WPUMFactory.getServiceUserFactory().getServiceUser(";cmadmin_service";); ResourceContext rContext = new ResourceContext(user); //4. Retrieve the collection for Resource using the resource context IResource aResource = resourceFactory.getResource(aRid, rContext); //5. Get Destination RID RID dRid = RID.getRID(destination); logger.errorT(dRid.getPath()); IResource dResource = aResource.copy(dRid, new CopyParameter()); dResource.setProperty(new Property(PropertyName.createDisplayname(), ";destination";)); logger.errorT(";After Copy";); } catch (ResourceException e) { logger.errorT(";ResourceException INSIDE copy(): "; + e.toString()); } catch (UserManagementException e) { logger.errorT(";UserManagementException INSIDE copy(): "; + e.toString()); } wdControllerAPI.getComponent().getMessageManager().reportSuccess(";Files are copied successfully.";);
