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).
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
One way would be to check out the uQuery Extensions from uComponents - they have a method you can run that might help: GetFollowingSiblingNodes()
-Tom
Hi Michael,
If you don't want to add packages to you solution you could try something like:
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
is working on a reply...