Copied to clipboard

Flag this post as spam?

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

  • Mikkel Johansen 116 posts 291 karma points
    Dec 04, 2015 @ 10:43
    Mikkel Johansen

    IContent property value

    Is it possible to typecast a NestedContent property when getting the value through a IContent property

    Example (that does not work) "items" is null

    var service = ApplicationContext.Current.Services.ContentService;
    var node =  service.GetById(nodeId);
    var items = node.GetValue<IEnumerable<IPublishedContent>>("products");

    If I try with node.GetValue("products") a fine JSON is returned.

    I have tried using the UmbracoHelper and TypedContent to get a IPublishedContent. But at that moment in code there is no "UmbracoContext.Current".


  • Lee Kelleher 3960 posts 15294 karma points MVP 11x admin c-trib
    Dec 05, 2015 @ 23:55
    Lee Kelleher

    Hi Mikkel,

    The raw JSON data is converted to an IPublishedContent list via NC's ProperyValueConverter. But that's only with published content, not from IContent properties.

    See the call to ConvertDataToSource in NC code.

    In order to prepare the raw JSON, you'd need to run it through NC's PropertyEditor call to ConvertDbToString method... see here.

    I'm curious what you're planning to do once you get the IEnumerable<IPublishedContent> items? No offence, it just seems interesting doing this from the IContent object.

    - Lee

  • Jeroen Breuer 4861 posts 12139 karma points MVP 3x admin c-trib
    Aug 16, 2016 @ 14:11
    Jeroen Breuer

    I needed to do the same thing. I have an unpublished item (so it's only available as IContent), but I want to do things like .GetPropertyValue<IEnumerable<IPublishedContent>>("courses") because it's a much easier API to use.

    I've wrote an extension method which can convert an IContent to an IPublishedContent:

    More info in this topic:

    So now I can do things like this:

    // Convert it to an IPublishedContent. So this IPublishedContent has the unpublished version.
    var publishedContent = content.ToPublishedContent();
    // Get the items which are selected on the node.
    var items = publishedContent.GetPropertyValue<IEnumerable<IPublishedContent>>("courses");

    I hope this will be useful for someone.


  • Poornima Nayar 106 posts 276 karma points MVP 3x c-trib
    Jul 25, 2017 @ 00:29
    Poornima Nayar

    Hi Jeroen,

    The content helper came across as very helpful. I am trying to convert some html to pdf upon the published event and my doc types heavily rely upon NC. Just was wondering whether you hit any issues with the helper at all?


  • Jeroen Breuer 4861 posts 12139 karma points MVP 3x admin c-trib
    Jul 25, 2017 @ 20:01
    Jeroen Breuer


    The code has been in production for over a year and I've never had any issues. Also blogged about it here:


  • Poornima Nayar 106 posts 276 karma points MVP 3x c-trib
    Jul 25, 2017 @ 20:08
    Poornima Nayar

    The helper class is very useful. I am going to use that as well.

  • nickornotto 322 posts 694 karma points
    Apr 27, 2018 @ 01:00

    Brilliant Jeroen, your extension helped me to resolve the same problem. Thank you!

  • Saba Tandashvili 29 posts 181 karma points
    Feb 27, 2019 @ 14:33
    Saba Tandashvili

    You rock, this class helped me so much, i was using JavaScriptSerializer.Deserialize for Icontent.Getvalue parse. Was a bit stupid way but working perfectly. Moved on your code since today, thanks for sharing.

  • Andrew Wilson 9 posts 79 karma points
    Mar 20, 2019 @ 11:35
    Andrew Wilson

    Your extension just helped me solve a similar problem! Thank you Jeroen!

  • Poornima Nayar 106 posts 276 karma points MVP 3x c-trib
    Jul 25, 2017 @ 20:09
    Poornima Nayar

    I think the core needs something of this kind. I have a quirky content structure due to the way the application needs to work and i am trying to do some processing (html->pdf) on save and publish. And this class has been helping me well so far!

Please Sign in or register to post replies

Write your reply to: