Search code examples
c#sharepointsharepoint-2013opencmisdotcmis

CMIS Sharepoint 2013 - Cannot Update Document


I cannot update a document using CMIS for Sharepoint 2013. I keep getting an error "The operation is attempting to update an object that is no longer current." and I am stuck as to why that is.

Please can you check what is wrong with my code below:

        Dictionary<string, string> parameters = new Dictionary<string, string>();
        parameters[DotCMIS.SessionParameter.BindingType] = BindingType.AtomPub;
        parameters[DotCMIS.SessionParameter.AtomPubUrl] = url;
        parameters[DotCMIS.SessionParameter.User] = username;
        parameters[DotCMIS.SessionParameter.Password] = password;
        parameters[SessionParameter.RepositoryId] = repositoryID;

        SessionFactory factory = SessionFactory.NewInstance();
        ISession session = factory.CreateSession(parameters);
        ICmisObject cmisobj = session.GetObject("12345");

        IDictionary<String, Object> properties = new Dictionary<String, Object>();
        properties["cmis:name"] = "MyNewName";

        IObjectId newId = cmisobj.UpdateProperties(properties);

Thanks for the reply. I tried adding the IOperationContext but I am still getting the same error. Am I implementing it wrong?

        SessionFactory factory = SessionFactory.NewInstance();
        ISession session = factory.CreateSession(parameters);

        IOperationContext oc = session.CreateOperationContext();
        ICmisObject cmisobj = session.GetObject("12345", oc);

        IDictionary<String, Object> properties = new Dictionary<String, Object>();
        properties["cmis:name"] = "MyNewName";

        IObjectId newId = cmisobj.UpdateProperties(properties);

Solution

  • That's a known SharePoint bug. It fails with this error if you include a change token (property "cmis:changeToken") in your update request. DotCMIS automatically adds this property in order to prevent lost updates.

    To exclude the change token you must not request it when get the object. Call GetObject() with an IOperationContext object, which has a property filter that not contains "cmis:changeToken". SharePoint will then accept the update request.