Copied to clipboard

Flag this post as spam?

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


  • Vishal G.P 62 posts 122 karma points
    Aug 26, 2011 @ 13:00
    Vishal G.P
    0

    How to get the documentType of a Document node via APi

    hey guys,

    i'm programming on the backend of umbraco... 

    i have the following code:  I want to know the DocumentType of my countryHome Document. I've tried several things but i cannot find how to get it as a string.. 

     

    var current = uQuery.GetDocument(pageId); //PageId is from current.Context.request['id']
                   
    var ancestors = uQuery.GetDocumentsByCsv(current.Path); //get all ancestors from the path and put them in List<Document>>
    if (ancestors.Count > 0)
    {                    
              Document countryHome  = ancestors[0];                      
            }

     

    ANy help is appreciated. Thanks in advance..

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Aug 26, 2011 @ 13:24
    Hendy Racher
    0

    Hi Wiske80,

    Had never thought of getting ancestors via the path csv ! (possibly slightly quicker than recursing up the tree with the .GetAncestorDocuments())

    You could either cast the Document to a Node and use the .NodeTypeAlias property, or:

    string docTypeAlias = countryHome.ContentType.Alias;

    HTH,
    Hendy

  • Vishal G.P 62 posts 122 karma points
    Aug 26, 2011 @ 14:11
    Vishal G.P
    0

    Fantastic Hendy.. thats works like a charm..  and yes getting the ancestors via path csv is really fast... i just stumbled upon it when looking through the uquery methods... It even omits the -1 node (content node).. so the first u get is the root node of the particular currentNode.. so its nice..

     

     

  • 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