Get all Documents under Content not just parent node
How do I get all document types under the content node not just the top most node under content? Like AncestorOrSelf but up one level?
Here's whats returning everything under the top leve node I'm under, but not its siblings:
var root = Model.AncestorOrSelf();
// Get all descendants, filter by type: var nodes = root.Descendants().Where("NodeTypeAlias == @0 || NodeTypeAlias == @1", "BlogPostMC", "BlogPostHCR");
Model.AncestorOrSelf() returns the site root. To get the the true root, do the following:
var root = Library.NodeById(-1); var nodes = root.Descendants();
FYI, getting the descendants of the entire site and then filtering them is a very expensive operation. We had a lot of sites running code like this and after a little while refactored the code so it didn't and it improved load time by 400%, so beware. You may want to look a different options for querying the info you need.
How about: uQuery.GetNodesByType("blogPostDocTypeAlias") ? (internally that uses XPath so is quick, and will return all blogposts wherever they are in the tree).
Get all Documents under Content not just parent node
How do I get all document types under the content node not just the top most node under content? Like AncestorOrSelf but up one level?
Here's whats returning everything under the top leve node I'm under, but not its siblings:
Model.AncestorOrSelf() returns the site root. To get the the true root, do the following:
FYI, getting the descendants of the entire site and then filtering them is a very expensive operation. We had a lot of sites running code like this and after a little while refactored the code so it didn't and it improved load time by 400%, so beware. You may want to look a different options for querying the info you need.
Thanks Douglas, any suggestions for a good alternative? I need to pull blogs abstracts from a multisite install to the main site...
Hi Amir,
How about: uQuery.GetNodesByType("blogPostDocTypeAlias") ? (internally that uses XPath so is quick, and will return all blogposts wherever they are in the tree).
HTH,
Hendy
is working on a reply...
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.