Stack Exchange
How to extract all pages from a structure group?
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         

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.

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.

However, this still does not explain why the app hangs when I call GetItems() without specifying the recursive option.

Can I ask what you try to achieve in the end?

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.
