cancel
Showing results for 
Search instead for 
Did you mean: 

Custom code development using CMIS

amittongaonkar
Champ in-the-making
Champ in-the-making
Hello All,

I am developing a custom .NET based application which needs to interact with the Alfresco system in place. I want to retrieve all the versions of a particular document along with all their metadata and pass them to my custom application.

I have written following code, but its giving me "Bad Request" error. I think I am getting error where there is some mismatch in the RepositoryId and ObjectId that is getting passed. I need your kind help to fix the same.

private IItemEnumerable<ICmisObject> GetChildren(IOperationContext context)
                    {
                        string objectId = "1a8fefd8-d99c-4df2-9a44-e66e2cadea2d";
                        INavigationService service = session.Binding.GetNavigationService();
                        IObjectFactory of = session.ObjectFactory;
                        IOperationContext ctxt = new OperationContext(context);
                        String folderId = session.GetObject("workspace://SpacesStore/0270f45a-b41a-41af-bab8-4951234817b9").Name;

                        service.GetFolderTree(session.RepositoryInfo.Id,"0270f45a-b41a-41af-bab8-4951234817b9",1000,context.FilterString,context.IncludeAllowableActions,context.IncludeRelationships,context.RenditionFilterString,context.IncludePathSegments

IObjectInFolderList children1 = service.GetChildren(session.RepositoryInfo.Id, objectId, context.FilterString, context.OrderBy, context.IncludeAllowableActions, context.IncludeRelationships, context.RenditionFilterString, context.IncludePathSegments, 10, 0, null);
                        PageFetcher<ICmisObject>.FetchPage fetchPageDelegate = delegate(long maxNumItems, long skipCount)
                        {
                            IObjectInFolderList children = service.GetChildren(session.RepositoryInfo.Id, objectId, context.FilterString, context.OrderBy, context.IncludeAllowableActions, context.IncludeRelationships, context.RenditionFilterString, context.IncludePathSegments, maxNumItems, skipCount, null);

                            // convert objects
                            IList<ICmisObject> page = new List<ICmisObject>();
                            if (children.Objects != null)
                            {
                                foreach (IObjectInFolderData objectData in children.Objects)
                                {
                                    if (objectData.Object != null)
                                    {
                                        page.Add(of.ConvertObject(objectData.Object, ctxt));
                                    }
                                }
                            }

                            return new PageFetcher<ICmisObject>.Page<ICmisObject>(page, children.NumItems, children.HasMoreItems);

                        };
                        return new CollectionEnumerable<ICmisObject>(new PageFetcher<ICmisObject>(context.MaxItemsPerPage, fetchPageDelegate));
                    }
3 REPLIES 3

muralidharand
Star Contributor
Star Contributor
Hi Amit,
What is your DOTCMIS version? If possible, please post your complete class file.

muralidharand
Star Contributor
Star Contributor
Hi Amit,
Please try this and let me know.
To retrieve all the versions of a particular document.


            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters[DotCMIS.SessionParameter.BindingType] = BindingType.AtomPub;
            parameters[DotCMIS.SessionParameter.AtomPubUrl] = "http://localhost:8080/alfresco/service/cmis";
            parameters[DotCMIS.SessionParameter.User] = "admin";
            parameters[DotCMIS.SessionParameter.Password] = "admin";
            SessionFactory factory = SessionFactory.NewInstance();
            ISession session = factory.GetRepositories(parameters)[0].CreateSession();
            // get the document using its noderef
            Document document = ((Document)session.GetObject("workspace://SpacesStore/b49fb618-76a1-4f19-91ac-37c8c39a2412"));
            IList<IDocument> documents = document.GetAllVersions();

            foreach(Document doc in documents )
            {
                Console.WriteLine("Document name : " + doc.Name + " and its version " + doc.VersionLabel);
            }


Hello Murali,

This really worked and I could get my code going with this. Many Thanks again for your extended support.. Smiley Happy