Getting a List of PageNodes with Specific Controls

Posted by Community Admin on 03-Aug-2018 16:11

Getting a List of PageNodes with Specific Controls

All Replies

Posted by Community Admin on 15-Sep-2011 00:00

I was having an issue writing some lambda code to get a list of pages with a specific control object type.

Say I am looking for the "widget" type
MyProject.NameSpace.ControlType

How would I write the lambda?

var pm = PageManager.GetManager();
var pnWithObjectType = pm.GetPageNodes()
    .Where(pn => pn.Page != null)   
    // unsure how to add this piece below
    // this does not compile
    .Where(pc => pc.Page.Controls.Where(control => control.ObjectType == "MyProject.NameSpace.ControlType"));

Posted by Community Admin on 17-Sep-2011 00:00

Hi James,

 Try this:

var pm = PageManager.GetManager();
            var pnWithObjectType = pm.GetPageNodes()
                .Where(pn => pn.Page != null)
                .Where(pd => pd.Page.Controls.Any(c => c.ObjectType.StartsWith(typeof(MyProject.Namespace.ControlType).FullName)));
Best wishes,
Svetoslav Petsov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 19-Sep-2011 00:00

This is exactly what I needed!  Throwing it on our utility class.  Thanks so much for your help.

This thread is closed