Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
With ContentService it was alway easy to get a node as IContent and get it's Children too. Children (or GetChildren()) is gone now. What's the best way to get all Children of a certain node when you have an IContent object?
The ContentService has a few methods that can help you out
There is a GetPagedChildren method that will return an IEnumerable of IContent items, based on the Id of a content item:
var contentId = 1234;
//is there children for this content id?
bool hasChildren = _contentService.HasChildren(contentId);
//get the first 100 children... and has an out variable giving you the total count
IEnumerable<IContent> children = _contentService.GetPagedChildren(contentId, 1, 100, out totalChildren);
//there is also a seperate ChildCount method
var childCount = _contentService.ChildCount(contentId)
With dependency injection, you can look at Sebastiaans posts in this thread for examples on how to do this:
Just a heads-up that the _contentService.GetPagedChildren pageIndex parameter starts at 0, so you'd technically be fetching the second page already.
I found the GetPagedChildren, but thought there should be any .Children() entension method.. But guess I will then have to use this one.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted