AnsweredAssumed Answered

How to upload new version of document in alfresco using DotCMIS and How to Show Version History Update..

Question asked by shivtechno on Oct 14, 2016
Latest reply on Oct 14, 2016 by kaynezhang

Hi

i am trying to dot this asked question by using below code .

                #region --Authendication Masters..

                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/api/-default-/public/cmis/versions/1.0/atom";

                parameters[DotCMIS.SessionParameter.User] = UserName;

                parameters[DotCMIS.SessionParameter.Password] = Password;

               

                SessionFactory factory = SessionFactory.NewInstance();

                ISession session = factory.GetRepositories(parameters)[0].CreateSession();

 

                #endregion

              

                if (file == null)

                {

                    ViewBag.Message = "Please upload document.";

                }

                else if (file.ContentLength > 20728650)

                {

                    ViewBag.Message = "File size exceeds maximum limit 20 MB.";

                }

                else

                {

                    Document doc = ((Document)session.GetObject("workspace://SpacesStore/" + objectId));

                    // define dictionary for document

                    IDictionary<string, object> properties = new Dictionary<string, object>();

                    properties.Add(PropertyIds.Name, file.FileName);

                    properties.Add(PropertyIds.ObjectTypeId, "cmis:document");

                    //properties.Add(PropertyIds.ObjectId, objectId);

                    properties.Add(PropertyIds.CheckinComment, CheckInComment);

                    //folder Path storing Version Document..

                    IFolder folder = (IFolder)session.GetObjectByPath("/VersionControlDir");

                    byte[] data = new byte[file.ContentLength];

                    file.InputStream.Read(data, 0, data.Length);

                    ContentStream contentStream = new ContentStream

                    {

                        FileName = file.FileName,

                        MimeType = file.ContentType,

                        Length = file.ContentLength,

                        Stream = new MemoryStream(data)

                    };

                  

                    folder.CreateDocument(properties, contentStream, DotCMIS.Enums.VersioningState.CheckedOut);

                    IObjectId ob = doc.CheckIn(true, properties, null, CheckInComment);

                }

            }

Outcomes