Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Gabe Alam 6 posts 96 karma points
    May 24, 2019 @ 17:37
    Gabe Alam

    ContentService GetPagedDescendants no results

    Umbraco 8

    I'm trying to get all nodes of a certain type - regardless of publish state (hence why I'm using ContentService). I figured I'd get all nodes and filter from there.

    From the code as well as other forum threads it seems like I want ContentService.GetPagedDescendants() - but I'm running into an issue where it returns 0 elements. Even more curiously, the out totalRecords does return the proper number.

    Here's my content structure:

    And the code:

    As you can see, descendants has 0 elements but returnCount is 3 (as is expected).

  • Bryna 66 posts 227 karma points
    May 24, 2019 @ 19:43

    I am also getting this, even when I pass in -1 for the rootNode.Id. I am able to do below:

    IEnumerable<IContent> z =  contentService.GetPagedDescendants(-1, 1, 1000, out totalStale).Where(x => x.Published).AsEnumerable<IContent>()

    But 0 results are returned. How 0dd. Does it work for you when you move the code into a Razor View and Use IPublishedContent instead? Depending on what you are trying to accomplish, this might be a viable alternative.

  • Gabe Alam 6 posts 96 karma points
    May 24, 2019 @ 19:46
    Gabe Alam

    I haven't tried anything with IPublishedContent as I need all IContent, not just published elements. This is being used in an on save handler so there's no view for it.

  • Thomas Hansen 96 posts 299 karma points
    Jul 05, 2019 @ 15:19
    Thomas Hansen

    Change our "pageIndex" to 0. instead or 1.

    Had the same problem, but @Martijn helped me with this :) !

    This is what I have:

    IEnumerable<IContent> Children = Services.ContentService.GetPagedDescendants(pageId, 0, 5, out long TotalChildren, null, Ordering.By("date", Direction.Ascending, null, true));
Please Sign in or register to post replies

Write your reply to: