I have also created a nice little class to make it easier to query the tree by using a pre-configured NodeSelectionParameters object. In the constructor, I pre-configure some of the properties to the settings that I use most often. here it is:
public class NSP : NodeSelectionParameters
{
public NSP():base()
{
CultureCode = TreeProvider.ALL_CULTURES;
this.MaxRelativeLevel = -1;
this.CombineWithDefaultCulture = true;
this.SiteName = CMSContext.CurrentSiteName;
this.SelectOnlyPublished = true;
}
public NSP(NSP config):this((NodeSelectionParameters)config)
{
}
public NSP(NodeSelectionParameters config)
{
this.OrderBy = config.OrderBy;
this.SelectAllData = config.SelectAllData;
this.SelectOnlyPublished = config.SelectOnlyPublished;
this.SelectSingleNode = config.SelectSingleNode;
this.SiteName = config.SiteName;
this.TopN = config.TopN;
this.Where = config.Where;
this.AliasPath = config.AliasPath;
this.ClassNames = config.ClassNames;
this.Columns = config.Columns;
this.CombineWithDefaultCulture = config.CombineWithDefaultCulture;
this.CultureCode = config.CultureCode;
this.MaxRelativeLevel = config.MaxRelativeLevel;
}
}
The way you can use this class is like so:
var tree = new TreeProvider();
var blogPosts = tree.SelectNodes(new NSP(){ ClassNames="cms.blogpost",OrderBy="BlogPostDate DESC",
AliasPath="/MyBlog/%" });
//See how you only need to set the properties that are different than what you use by default? This has saved me a bunch of time when writing a lot of tree selection queries.