Alfresco以编程方式导航到正确的文件夹

时间:2013-03-21 07:04:48

标签: c# alfresco cmis dotcmis

我对Alfresco和dotCMIS库有疑问。基本上我想到一个特定的文件夹并创建一个文档。

此时我有以下代码(我知道它很乱,但它是用于测试):

 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);

                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

它只是打开一个根文件夹,这意味着我在'alfresco'例如,然后我必须导航到另一个子文件夹然后另一个,然后我最终到达: /图书馆,/团体,/新闻组......等 在图书馆我可以打开“我的文件夹”,但有没有更简单的方法来打开/ Library / MyFolder而不是真正通过所有图层获取正确的文件夹...?

我可以做点什么...... session.GetFolderByName("MyFolder")

我也不能依赖ID,例如在其他门户网站中为文件夹随机生成的ID可能不同,所以我不能说GetFolderById(..);

所以任何想法?

1 个答案:

答案 0 :(得分:1)

我对DotCMISClient并不是很熟悉,但如果你看一下整体服务(应该通过客户端提供),那么你会看到2个可以解决这个问题的服务

  1. GetObjectByPath
  2. Query
  3. 如果类型为cmis,则查询非常简单:文件夹和名称为“MyFolder”。