Copied to clipboard

Flag this post as spam?

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


  • Simon Dingley 1474 posts 3431 karma points c-trib
    Mar 31, 2009 @ 12:28
    Simon Dingley
    0

    Get Parent Node(s) in Custom DataType

    I have a custom datatype using umbraco user control wrapper which is used in both front and back end. In the backend I need to walk up the tree to find the closest node that has a specific property set and set that as the selected item in my datatype - any ideas?

    I understand I can use umbraco.library.GetXmlNodeById(Request.QueryString["id"]) to get the current node but not sure where to go from here?

    Any help would be appreciated.

    Thanks, Simon

  • Comment author was deleted

    Mar 31, 2009 @ 12:35

    I suggest you use

    umbraco.cms.businesslogic.web.Document

    Fetch the current

    umbraco.cms.businesslogic.web.Document current = new umbraco.cms.businesslogic.web.Document((int)Request.QueryString["id"]);

    and then use a while loop to look for the closest node with the specific property set

  • Comment author was deleted

    Mar 31, 2009 @ 12:37

    loop will look something like

    umbraco.cms.businesslogic.web.Document parent = current.parent;

    while(parent.getProperty("propertyalias").value == null)
    {
    parent = parent.parent;
    }

  • Peter Gregory 408 posts 1614 karma points MVP 3x admin c-trib
    Mar 31, 2009 @ 12:38
    Peter Gregory
    0

    Tim beat me to it. I was going to say use umbraco.cms.businesslogic.Content and use the parent property on that. But Document Inherits from Content so its the same thing really.

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Mar 31, 2009 @ 13:18
    Simon Dingley
    0

    Tim, thanks for the pointer which has got me to a working solution.

    [code] Document currentDoc = new Document(Convert.ToInt32(Request.QueryString["id"]));

    while (currentDoc.getProperty("Branch") == null)
    {
    currentDoc = new Document(currentDoc.Parent.Id);
    }[/code]

    currentDoc.Parent returns a CMSNode and not another document so my question now is how efficient is the above workaround and is there a better way of achieving the same?

  • Peter Gregory 408 posts 1614 karma points MVP 3x admin c-trib
    Mar 31, 2009 @ 13:57
    Peter Gregory
    0

    From my little play around there doesnt seem to be a efficient way other than creating a new document from the CMSNode.Id.

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Mar 31, 2009 @ 15:41
    Simon Dingley
    0

    Thanks for looking Peter

  • Daniel Lindstrom 454 posts 271 karma points
    Nov 25, 2011 @ 09:25
    Daniel Lindstrom
    0

    Hello

    Is Simons solution still the prefered way of doing this? 

Please Sign in or register to post replies

Write your reply to:

Draft