Hi,

 

Can you send me sample code to update a same file with different version. My code is like this when I am uploading the file for first time its working fine. How to update it with different version.

 

 

if (mimeType == null) mimeType = "application/octet-stream";

                                //if (!roseMode.hasNode("AmitNode1")) {

                                      try{

                                      Node fileNode = null;

                                           

                                           if(!roseMode.hasNode(file.getName())){

                                               fileNode = roseMode.addNode(file.getName(), "nt:file");

                                                                                        }

                                           else{

                                               fileNode = roseMode.getNode(file.getName());

                                              }

 

                                      Node resNode = null;//fileNode.addNode("jcr:content", "nt:resource");

                                           if(!fileNode.hasNode("jcr:content")){

                                             resNode = fileNode.addNode("jcr:content", "nt:resource");

 

                                           } else{

                                               resNode = fileNode.getNode("jcr:content");

                                            }

 

                                    

                                      resNode.setProperty("jcr:mimeType", mimeType);

                                      resNode.setProperty("jcr:encoding", "");

                                      resNode.setProperty("jcr:data", new FileInputStream(file));

                                      Calendar lastModified = Calendar.getInstance();

                                      lastModified.setTimeInMillis(file.lastModified());

                                      resNode.setProperty("jcr:lastModified", lastModified);

                                      fileNode.addMixin("mix:versionable");

                                      fileNode.checkout();

                                      jcrSession.save();

                                      fileNode.checkin();

                                                                                   VersionHistory history = fileNode.getVersionHistory();

                                                 VersionIterator iter = history.getAllVersions();

                                                 iter.skip(1);

 

                                               while(iter.hasNext()) {

                                                 Version version = (Version) iter.nextVersion();

                                                 NodeIterator iter1 = version.getNodes();

 

                                                     if (iter1.hasNext()) {

                                                       Node no = iter1.nextNode();

                                                       out.println("Version saved on " +

                                                                            version.getCreated().getTime().toString() +

                                                                            " version no is  " +

                                                                            version.getName());

                                                      }

 

                                               }

 

 

 

Thanks & Regards

Amit Bhattacharjee