I have a solution where I try to match a node with a name from another db.
I have a tree with subpages and multiple levels and I want to traverse the whole tree and find a node with a certain name.
Im trying to use the right syntax to search all nodes. The root node is a separate tree so I've hardcoded to the Id:
var home = Umbraco.Content(1957); foreach (var childPage in home.Descendants.Where("NodeTypeAlias == @0 && Name = @1", "Product","The dynamic name im trying to find"){}
I know it's not very "Linq-y", but for this I'd try using an XPath query.
Something like this...
var homeId = 1957;
var docTypeAlias = "Product";
var dynamicName = "The dynamic name im trying to find";
var xpath = string.Format("id({0})//{1}[@isDoc and @nodeName = '{2}']", homeId, docTypeAlias, dynamicName);
var nodes = Umbraco.TypedContentAtXPath(xpath);
foreach (var node in nodes)
{
// do something
}
Just in case you didn't know about the id() bit ... it is quite powerfully, it's a super-fast way of returning a node :-)
Get node with certain name
Hi all!
I have a solution where I try to match a node with a name from another db.
I have a tree with subpages and multiple levels and I want to traverse the whole tree and find a node with a certain name.
Im trying to use the right syntax to search all nodes. The root node is a separate tree so I've hardcoded to the Id:
But im not getting any result?
Hi froad,
I know it's not very "Linq-y", but for this I'd try using an XPath query.
Something like this...
I hope this helps?
Cheers,
- Lee
That worked perfectly! Thx!
is working on a reply...