如何从一个使用coreservices的文件夹获取组件


1

我有一个文件夹,其中有子文件夹和组件。现在我只想检索使用指定模式的组件。如何使用核心服务来执行此操作。

6

尝试这样:

using System.Xml.Linq; 
using Tridion.ContentManager.CoreService.Client;    

... 

      string folderUri = ""; 
      string schemaUri = ""; 

      OrganizationalItemItemsFilterData filter = new OrganizationalItemItemsFilterData(); 
      filter.ItemTypes = new ItemType[] { ItemType.Component }; 
      filter.ComponentTypes = new ComponentType[] { ComponentType.Normal }; 
      filter.Recursive = true; 

      XElement items = Client.GetListXml(folderUri, filter); 
      foreach (XElement item in items.Elements()) 
      { 
       ComponentData component = Client.Read(item.Attribute("ID").Value, null) as ComponentData; 

       if (component.Schema.IdRef.Equals(schemaUri)) 
       { 

        // Do something with components of specific schema 

       } 

      } 

客户端变量的类型SessionAwareCoreServiceClient的。您可以在博客上找到更详细的代码说明http://codedweapon.com/2013/03/changing-components-schemas-with-core-service/

类似的东西已经在帖子上询问Get all component from selected folder and subfolder based on Schema