Snow Queen
Snow Queen

Reputation: 21

Retrieving a list of Tridion 2009 components with a specific value and schema without using search

I would like to create a .NET page residing on the CMS server that shows all components that are based on a specific Schema(tcm:3-3-8) and from a specific Publication(tcm:0-3-1) including BluePrinted and Localized items, but only if they have the value "http://www.google.com" for the field "URL" in that Schema.

Is this possible, without using the search service as this is rather slow and unreliable?

Upvotes: 1

Views: 302

Answers (3)

Mark Richardson
Mark Richardson

Reputation: 53

I have not had any chance to test it, but something like this

    Common common = new Common();
    TDSE tdse = new TDSE();
    ListRowFilter ComponentFilter = tdse.CreateListRowFilter();



    Schema schema = (Schema)common.getObject("tcm:126-238630-8", ItemType.ItemTypeSchema);
    ComponentFilter.SetCondition("ItemType", ItemType.ItemTypeComponent);
    ComponentFilter.SetCondition("Recursive", true);

    XDocument doc = common.ReadXML(schema.Info.GetListUsingItems(ListColumnFilter.XMLListID, ComponentFilter));
    List<Component> MatchedComponents = new List<Component>();

    XmlNamespaceManager NS = new XmlNamespaceManager(new NameTable());
    NS.AddNamespace("tcm", "http://www.tridion.com/ContentManager/5.0");
    NS.AddNamespace("Content", "uuid:4432F3C3-9F3E-45E4-AE31-408C5C46E2BF");
    foreach (XElement component in doc.XPathSelectElements("/tcm:ListUsingItems/tcm:Item", NS))
    {
        Component comp = common.getComponent(component.Attribute("ID").Value);

        XDocument compDoc = common.ReadXML(comp.GetXML(XMLReadFilter.XMLReadData));
        foreach (XElement compNode in compDoc.XPathSelectElements("/tcm:Component/tcm:Data/tcm:Content/Content:Content/Content:feederUrl", NS))
        {
            MatchedComponents.Add(comp);
        }
    }

Upvotes: 0

Siva Charan
Siva Charan

Reputation: 18064

Your search might be slow because of not indexing the search collection.

You should do indexing the search collection on regular intervals for better and fast results.

Upvotes: 2

Nuno Linhares
Nuno Linhares

Reputation: 10234

That's an expensive operation to do because of the cost of opening each individual component to check the value of a field, but certainly do-able.

  1. Get the schema object
  2. Get a list of components that use this schema (WhereUsed on the schema with filter on ItemType = component)
  3. Open each component and check the value for the field(s), add to a List<Component> if it matches
  4. Display list (possibly using a ASP.NET GridView)

Upvotes: 1

Related Questions