Copied to clipboard

Flag this post as spam?

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


  • Avraham Kahana 22 posts 56 karma points
    May 14, 2015 @ 15:12
    Avraham Kahana
    1

    How to get the name of a property via IPublishedProperty ?

    When looping over a node Properties property (a collection of IPublishedProperty object), I was hoping I could get the property name along with its value. But to my surprise, IPublishedProperty does not offer this data. Only the property alias and its value.

    How do I get then the node's properties names ? I need to return a response with a key/value list of the node's properties, by name and value.

    Thanks in advance.

  • Avraham Kahana 22 posts 56 karma points
    May 18, 2015 @ 15:22
    Avraham Kahana
    0

    Anyone?

  • Mehul Gajjar 48 posts 172 karma points
    May 19, 2015 @ 08:55
    Mehul Gajjar
    0

    Hi Avraham,

    have you look Umbraco Helper , kindly check below link

    https://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/

    i am not sure but it will help to get node and its property by name.

    hope this will help you.

    Regards,

    Mehul Gajjar.

  • Avraham Kahana 22 posts 56 karma points
    May 19, 2015 @ 10:20
    Avraham Kahana
    1

    I am already using the umbraco helper, more precisely, its TypedContent method, by which I get one IPublishedContent object. I then loop over the Properties of the latter, which means I loop over IPublishedProperty elements. So, my problem is: how to access the property's name? IPublishedProperty does not expose it!

    Here's my code. For the time being, I am using PropertyTypeAlias, but I need the property name, instead.

    List<dynamic> nodeProperties = new List<dynamic>();
    IPublishedContent content = Umbraco.TypedContent(umbracoNodeId);
    
    if (content != null)
    {
        foreach (IPublishedProperty property in content.Properties)
        {
            nodeProperties.Add(new { key = property.PropertyTypeAlias, value = property.Value });
        }
    }
    
  • Mehul Gajjar 48 posts 172 karma points
    May 19, 2015 @ 11:41
    Mehul Gajjar
    102

    Hi Avraham,

    kindly check the below

     var docType = DocumentType.GetByAlias(umbNode.NodeTypeAlias);
                foreach (var propertyType in docType.PropertyTypes)
                {
                    var propName = propertyType.Name;
                    var propValue = umbNode.GetProperty(propertyType.Alias).Value;
                }
    

    Hope this will help you.

    Regards,

    Mehul Gajjar.

  • Avraham Kahana 22 posts 56 karma points
    May 19, 2015 @ 12:19
    Avraham Kahana
    2

    Nice! Thanks Mehul! This is what I needed :-)

    Just a minor improvement to your answer:

    DocumentType type is obselete. I am using instead Services.ContentTypeService.GetContentType, which returns IContentType, which contains a collection of PropertyType objects at "PropertyTypes".

    Another thing: if anyone else ends up here and, like me, is interested in a given document type properties only - and not the inheriting ones - then IContentType.PropertyTypes will give you just that.

  • Mehul Gajjar 48 posts 172 karma points
    May 19, 2015 @ 12:53
    Mehul Gajjar
    0

    Hi,

    Glad to hear that you got what you want.

    Cheers,

    Mehul Gajjar.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies