cancel
Showing results for 
Search instead for 
Did you mean: 

Delete specific document version

horia
Champ in-the-making
Champ in-the-making
Hi,

Is it possible to programatically delete a specific document version in Alfresco?

It seems you can only delete all versions of a doc (and the API is confusing, you have two methods that do the same thing, delete and deleteAllVersions)

Thanks
4 REPLIES 4

kaynezhang
World-Class Innovator
World-Class Innovator
You can use 

org.apache.chemistry.opencmis.client.api.Session.delete(ObjectId,false) method

or

org.apache.chemistry.opencmis.client.api.Document.delete(false) method

for example

         AlfrescoDocument document = (AlfrescoDocument) session
               .getObjectByPath("/TESTFOLDER1/20130822.doc");      
         List<Document> versions = document.getAllVersions();
         for(int i=0;i<versions.size();i++){
            Document version = versions.get(i);
            if("1.1".equals(version.getVersionLabel())){
               version.delete(false);
            }
         }

rachana
Champ in-the-making
Champ in-the-making
Hi Kaynezhang

Can you please tell me how i implement this. I am trying this from past many days but not getting any result. Please tell me how i use this???

kaynezhang
World-Class Innovator
World-Class Innovator
I have already pasted the example

         AlfrescoDocument document = (AlfrescoDocument) session.getObjectByPath("/TESTFOLDER1/20130822.doc");      
         List<Document> versions = document.getAllVersions();
         for(int i=0;i<versions.size();i++){
            Document version = versions.get(i);

            if("1.1".equals(version.getVersionLabel())){
               version.delete(false);
            }
         }

rachana
Champ in-the-making
Champ in-the-making
Hi Kaynezhang

Thanks allot for your reply.
Its working fine. i am executing this code in CMIS Workbench and its deleting specific version of alfresco document that is present in repository. Now i am not getting where i save this code? Is every time i have to execute this script through Groovy console for deleting the version? Please help me.

Thank u so much