Question

I have a question regarding Alfresco and dotCMIS library. Basically i would like to get to a particular folder and create there a document.

At this time i have the following code (i know it is messy, but it was for testing):

 Dictionary<string, string> parameters = new Dictionary<string, string>();

            parameters[SessionParameter.BindingType] = BindingType.AtomPub;
            parameters[SessionParameter.AtomPubUrl] = "http://webadress:2005/alfresco/service/cmis";
            parameters[SessionParameter.User] = "amdin";
            parameters[SessionParameter.Password] = "admpsw";

            SessionFactory factory = SessionFactory.NewInstance();
            IList<DotCMIS.Client.IRepository> repositories = factory.GetRepositories(parameters);
            DotCMIS.Client.ISession session = repositories[0].CreateSession();

            foreach (ICmisObject cmisObject in rootFolder.GetChildren())
            {
                Console.WriteLine(cmisObject.Name);
                if (cmisObject.Name.Equals("AlfresCO"))
                {
                    var type = cmisObject.GetType();
                    IFolder circabcfolder = cmisObject as IFolder;
                    foreach (ICmisObject obj in circabcfolder.GetChildren())
                    {
                        Console.WriteLine(obj.Name);
                        if (obj.Name.Equals("SubFolder1"))
                        {
                            IFolder circabcfolder2 = obj as IFolder;
                            foreach (ICmisObject obj2 in circabcfolder2.GetChildren())
                            {
                                Console.WriteLine(obj2.Name);

                                foreach (ICmisObject obj3 in (obj2 as IFolder).GetChildren())
                                {
                                    Console.WriteLine(obj3.Name);
                                    if (obj3.Name.Equals("Library"))
                                    {
                                        foreach (ICmisObject obj4 in (obj3 as IFolder).GetChildren())
                                        {
                                            Console.WriteLine(obj4.Name);
                                            if (obj4.Name.Equals("MyFolder"))
                                            {
                                                IDictionary<string, object> properties2 = new Dictionary<string, object>();
                                                properties2[PropertyIds.ObjectTypeId]= "cmis:folder";
                                                properties2[PropertyIds.Name] = "Test Folder";

                                                IFolder newFolder = (obj4 as IFolder).CreateFolder(properties2);

                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

It just opens a root folder, this means i'm in 'alfresco' for example, then i have to navigate to another sub folder and then another one, and then finally i get to: /Library, /Groups, /Newsgroups ... etc. And in Library i can open "My Folder", but is there a more easier way to just open /Library/MyFolder instead of really going through all the layers getting the right folder ...?

Can i do something like .. session.GetFolderByName("MyFolder")

I can't also rely on ID, as for example in other portal the ID that is randomly generated for a folder can be different, so i cannot say GetFolderById(..);

So any idea?

Was it helpful?

Solution

I'm not really familiar with the DotCMISClient, but if you look at the total services (which should be available through the client) then you'll see 2 services which will do the trick

  1. GetObjectByPath
  2. Query

The query is quite easy where type is cmis:folder and name is "MyFolder".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top