cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a copy of a file ?

darkhope
Champ in-the-making
Champ in-the-making
Hi,

Sorry if I made a mistake about the forum where I post my problem, and sorry for my poor english Smiley Happy. Smiley Surprisedops:

I want to get some informations about a file or folder, but I don't know how to do.
For my example, I have a file plop.txt in the folder /app:company_home


My function:
public static Reference copyFile(String file1Path, String file2Name, String file2Folder) throws Exception{
        // Get the content service
          ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
          Reference file1Ref = new Reference(STORE, null, file1Path);
           Content[] readResult = contentService.read(
                     new Predicate(new Reference[]{file1Ref}, STORE, null),
                     Constants.PROP_CONTENT);
           Content content = readResult[0];
          //Create new content in the repository
          createNewContent(file2Name, ContentUtils.getContentAsString(content),file2Folder);
          return content.getNode();
    }


I call my function with this:
copyFile("/app:company_home/plop.txt", "file copy.txt", "/app:company_home");
with the address of the file in first, the name of the new file in second and to finish the path where to create the copy.
So, I would like to search the file "plop.txt" to read it and copy its content into a new file.
But I have a problem with the file1Ref Reference. I would like that it takes informations of the file to open it, but it does not do anything…


Thanks for helping me  Smiley Surprisedops: .
1 REPLY 1

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

It is possible to copy files on the server using the update method on the repository service and creating a CML statement containing a copy operation.

Hope this helps,
Roy