Copied to clipboard

Flag this post as spam?

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


  • Michael Falch Madsen 70 posts 92 karma points
    Oct 27, 2011 @ 20:42
    Michael Falch Madsen
    0

    following-sibling

    How would i go around getting currentNode's following-sibling in C# using NodeFactory?

    I'm using 4.5.2 so no razor

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Oct 27, 2011 @ 20:55
    Tom Fulton
    0

    One way would be to check out the uQuery Extensions from uComponents - they have a method you can run that might help:  GetFollowingSiblingNodes()

    -Tom

  • Jesper Hauge 298 posts 487 karma points c-trib
    Oct 27, 2011 @ 23:56
    Jesper Hauge
    1

    Hi Michael,

    If you don't want to add packages to you solution you could try something like:

    string xPath = string.Format(@"/root//node[@id='{0}']/following-sibling::*[1]", Node.GetCurrent().Id.ToString())
    var iterator = umbraco.library.GetXmlNodeByXPath(xPath);
    Node sibling;
    if (iterator.MoveNext()) {
    var id = 0;
    if (int.TryParse(iterator.Current.GetAttribute("id", ""), out id))
    sibling = new Node(id);
    }

    Note that I haven't tested this code, so I'm not sure if syntax is correct and so forth, but I thought it could give you an idea.

    You could also look into using the Node.GetCurrent().Parent.Children collection, which is of type umbraco.presentation.nodeFactory.Nodes. But I find this collection rather cumbersome to work with. (Maybe others agree because in v 4.7.0 (and 4.6.1), this collection has been replaced by the much easier to use umbraco.NodeFactory.Node.ChildrenAsList property which is of type System.Collections.Generic.List<umbraco.interfaces.INode>

    So if you're going to do a lot of work on Nodes in .NET code I'd really recommend upgrading from 4.5.2 to 4.7.1, just to be able to use the vastly improved NodeFactory API present in the latest version. (or even the DynamicNode API which is a whole other ballgame).

    Regards
    Jesper Hauge 

Please Sign in or register to post replies

Write your reply to:

Draft