Copied to clipboard

Flag this post as spam?

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


  • Sadid Khan 1 post 21 karma points
    May 24, 2015 @ 12:13
    Sadid Khan
    0

    get property names and alias of a document type

    enter image description here

    i have a scenerion to make a table that is given below..

    i have a document type named packages.. that contains a list of property

    Maximum Number Of Nodes, Time, Price, Type etc.

    and these are the content type..

    Trial , Academic, Basic, standard

    to create the table i have to loop through the property values and also the name.. i can get the values.. but here i need also the property names.. how can i achieve this..

    var content = contentService.GetById(1234); foreach(var property in content.Properties){ string alias = property.Alias; object value = property.Value; Guid version = property.Version; }

    it is possible to get alias by doing this but i don't want to hardcode the ID

    any better solution... thanks in advance

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

    Hi Sadid,

    Kinldy 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.

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    May 25, 2015 @ 14:33
    Sebastiaan Janssen
    0

    Just a huge, huge warning: both of these methods avoid the cache and will grab data from the database each time, this is killing for performance. Please consider using TypedContent, see reference docs: https://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/

    You can avoid hardcoding the Id if you know from where in the tree you want to select the startnode. If you can show an example of what your tree looks like, what each node's document type is and on what page you want to show this information is then that would help.

Please Sign in or register to post replies

Write your reply to:

Draft