AnsweredAssumed Answered

How to create documents with version using cmis in c#?

Question asked by divyabharathipalivela on Jul 2, 2014
Latest reply on Jun 24, 2015 by dhamayandhi
Hi Team,


I am trying to create documents with versioning. I did upto check out. While checking I am getting conflict. First I am creating documents from that method i am passing docid/path as parameter to createdocument_version method. In that I am performing checkout .Upto that it is working fine. Please help me to solve that one .

Sample Code :
private void ConnectingUsingAtomPub_CreateDocument_Version(string path,IFolder newFolder)
        {

            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters[DotCMIS.SessionParameter.BindingType] = BindingType.AtomPub;
            parameters[DotCMIS.SessionParameter.AtomPubUrl] = "http://127.0.0.1:8080/alfresco/cmisatom";
            parameters[DotCMIS.SessionParameter.User] = "admin";
            parameters[DotCMIS.SessionParameter.Password] = "root";
            SessionFactory factory = SessionFactory.NewInstance();
            ISession session = factory.GetRepositories(parameters)[0].CreateSession();
          
            string formattedName = Path.GetFileName(fileUpload1.FileName);
          
            // get / define the document, which you would want to update with versioning
            Document doc = ((Document)session.GetObjectByPath(path));
            string objId = string.Empty;
            try
            {

                // checkout the doc
                IObjectId Iobj = doc.CheckOut();
                objId = Iobj.Id;

                Response.Write("Checked out doc ID: " + objId);
            }
            catch (Exception cbe)
            {
                // cancel the checkout incase of exception
                doc.CancelCheckOut();
                Response.Write("Exception checking out; must be checked out already: " + cbe.Message);
            }

            // define dictionary for document
            IDictionary<string, object> properties = new Dictionary<string, object>();
            properties.Add(PropertyIds.Name, formattedName);
            properties.Add(PropertyIds.ObjectTypeId, "cmis:document");
            properties.Add(PropertyIds.ObjectId, objId);
            IFolder folder = session.GetRootFolder();

            // define new document stream object
            ContentStream contentStream = new ContentStream
            {
                FileName =formattedName,
                MimeType = "application/msword",
                Length = fileUpload1.FileBytes.Length,
                Stream = new MemoryStream(fileUpload1.FileBytes)
            };

            // create/update the document with new stream & version
            newFolder.CreateDocument(properties, contentStream, DotCMIS.Enums.VersioningState.CheckedOut);

            // finally check in the document
            IObjectId ob = doc.CheckIn(true, properties, null, "testing divya checking");

        }

Outcomes