Copied to clipboard

Flag this post as spam?

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


  • Mihir Ajmera 32 posts 145 karma points
    Oct 15, 2019 @ 05:46
    Mihir Ajmera
    0

    Get All Published & Unpublished Content in the custom property API Call in Umbraco 8.1.4

    Hello All,

    I have created one custom property for radio button selection which I got all published content in the list but as per my requirement, I need to get all published and Unpublished contents of the parent in the list in the back office.

    In Umbraco 7 I got all children using the below code.

    var contentService = ApplicationContext.Services.ContentService;
        var contentTypeService = ApplicationContext.Services.ContentTypeService;
    
        var list = contentService.GetChildren(Id).Where(con => con.Name.Contains(Key) || Key == "")
           .Select(x => new MyContent { ID = Convert.ToInt32(x.Id), Name = x.Name });
    

    Now, I do the same process in the Umbraco 8 then I can`t get the list because ApplicationContext Service support removes in the Umbraco 8.

    So, anyone has any idea about how to get all parent nodes children of published and unpublished in the list using Umbraco 8.1.4 version?

    Thanks in advance.

  • Steve Megson 151 posts 1024 karma points MVP c-trib
    Oct 15, 2019 @ 07:43
    Steve Megson
    0

    The services still exist and work in pretty much the same way, but the way you access them has changed. Since you're writing a custom property editor, you can create a constructor for your class with parameters for the services you need, and Umbraco will provide them. Something like:

    public class MyPropertyEditor : IDataEditor
    {
        private readonly IContentService _contentService;
    
        public MyPropertyEditor(IContentService contentService)
        {
            _contentService = contentService;
        }
    
        ...
    }
    
  • Mihir Ajmera 32 posts 145 karma points
    Nov 27, 2019 @ 12:40
    Mihir Ajmera
    0

    Hello Steve,

    Using the Above solution I get only published content data with a single node, not any method found which gets all children content also.

     var contentData = _contentService.GetById(Id);
    

    I need to get the Unpublished node in the custom property for the back office.

    If you have any other solution then tell me so I can try and check it.

    Thanks in Advance.

  • Steve Megson 151 posts 1024 karma points MVP c-trib
    Nov 27, 2019 @ 15:53
    Steve Megson
    100

    Something like this should work:

    var children = _contentService.GetPagedChildren(Id, 0, Int32.MaxValue, out _);
    
  • Mihir Ajmera 32 posts 145 karma points
    Dec 04, 2019 @ 05:29
    Mihir Ajmera
    0

    Hi Steve Megson,

    Thanks for giving me a useful code.

    Now I get all Unpublished content in the custom property.

Please Sign in or register to post replies

Write your reply to:

Draft