0

I have a specific structure group from which I want to extract all pages and components (recursively). It is passed to a method as a RepositoryLocalObject.

private void ExtractPagesAndComponentsFromStructureGroup(RepositoryLocalObject transItem)
    {
        if (transItem == null)
        {
            return;
        }
        if (transItem.Id.ItemType == Tridion.ContentManager.ItemType.Page)
        {
            // some code
            return;
        }
        if (transItem.Id.ItemType == Tridion.ContentManager.ItemType.Component)
        {
            // some code
            return;
        }

        // if the item is a structure group, the recursive method is performed
        var structureGroup = transItem as StructureGroup;

        foreach (var structureGroupItem in structureGroup.GetItems())
        {
            ExtractPagesAndComponentsFromStructureGroup(structureGroupItem);
        }            
    }

The problem is that the moment .GetItems() is called, the execution hangs and nothing seems to happen. Any ideas how I can resolve this? I also tried a different approach for the recursive call, but the result is the same:

// if the item is a structure group, the recursive method is performed
        var structureGroup = transItem as StructureGroup;
        var structureGroupItems = structureGroup.GetItems(new OrganizationalItemItemsFilter(this.session)
                {
                    ItemTypes = new[] { Tridion.ContentManager.ItemType.Page, Tridion.ContentManager.ItemType.Component }                        
                });


        foreach (var structureGroupItem in structureGroupItems)
        {
            ExtractPagesAndComponentsFromStructureGroup(structureGroupItem);
        }   

PS: I know the code is a little error-prone (it will fail if the object is anything else than page,component and structure group) but I'm testing it only with a structure group object so it should work fine

  • 1
    Component can not be placed to SG...It can be only in folders. Also note OrganizationalItemItemsFilter has Recursive flag, which allows you to skip your recursion. – Syav4eg Jun 12 '14 at 10:41
  • My bad about the component part, still it doesn't affect the outcome. I read somewhere that the Recursive option does not work on OrganizationalFilter. However, I just tested it and works fine. – stann1 Jun 12 '14 at 10:58
  • However, this still does not explain why the app hangs when I call GetItems() without specifying the recursive option. – stann1 Jun 12 '14 at 10:59
  • 1
    Can I ask what you try to achieve in the end? – user219 Jun 15 '14 at 9:06
  • Recursive option doesn't work on non-organizational items (so not pages). The second approach doesn't quite match the first -- isn't that filtering for Pages and Components and so the recursive call should miss nested SGs and fail on var structureGroup = transItem as StructureGroup;. Let me know if I'm reading that wrong and if there was an answer to this question. – Alvin Reyes Aug 6 '14 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.