Copied to clipboard

Flag this post as spam?

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


  • Braydie 148 posts 346 karma points
    Jul 30, 2013 @ 17:42
    Braydie
    0

    Using ContentService to get a list Ancestors of certain Content Type

    I'm doing my own sorting of pages in the admin site and have an old event handler that was working against Document. I've since upgraded to 6.1.x and am looking at rewriting my event handlers to use the new Content Service. 

    I'm running into difficulty in retrieving ancestors of a page based on their content type alias. My code is throwing a null reference exception and I can't quite decide if I've found a bug or not....

    My event handler is firing on ContentService.Saved.

    ...global::Umbraco.Core.Events.SaveEventArgs Args)
    {
    
       var Service = new ContentService();
       using (var SortService = new nodeSorter())
       {
          var ContactFolder = Service.GetAncestors(e.SavedEntities.First()).FirstOrDefault(x=>x.ContentType.Alias == DocumentTypes.CONTACT_FOLDER);
    
          ...
       }
    }

    So I'm getting the null reference exception when trying to access the ContentType property. Can anyone help?

    Thanks,

    Braydie

Please Sign in or register to post replies

Write your reply to:

Draft