I’m currently working on rebuilding the http://dotnetda.org site using Umbraco and I have created the usual assortment of document types: speakers, meetings, sponsors, etc. For meetings, the name of the node is simply the session title. Unfortunately, this means that finding a meeting requires knowing the session title and I want the node text to be more descriptive and include the date as well. I can use the Umbraco API and write a little code to do this for me.
To start, I added the following using statements:
using System;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic;
using umbraco.cms.presentation.Trees;
Then, I created a class that inherits from ApplicationBase. By simply inheriting from ApplicationBase, Umbraco will automatically load the class during initialization:
public class TreeEvents : ApplicationBase
{
}
Next, I added a TreeEvents constructor and handled the BaseTree.BeforeNodeRender event:
public TreeEvents()
{
BaseTree.BeforeNodeRender += BaseTree_BeforeNodeRender;
}
And finally I implemented the BaseTree_BeforeNodeRender method with the necessary logic to update the node’s Text property if it’s a meeting:
void BaseTree_BeforeNodeRender(
ref XmlTree sender, ref XmlTreeNode node, EventArgs e)
{
if (node.NodeType == "content")
{
var content = new Content(int.Parse(node.NodeID));
if (content.ContentType.Alias == "Meeting")
{
var startDate = content.getProperty("meetingStartDate")
.Value.ToString();
var date = DateTime.Parse(startDate);
node.Text = String.Format("{0:MM/dd/yyyy} {1}",
date,
node.Text
);
}
}
}
First, I ensure that I’m dealing with a content node, then I grab the content item based on NodeID. If the content type alias is Meeting, I parse the meetingStartDate property and prepend it to the node’s existing text.
The final result is that I can now see the meeting date which will make meetings much easier to find:

Final Code
using System;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic;
using umbraco.cms.presentation.Trees;
namespace Netda.Umbraco
{
public class TreeEvents : ApplicationBase
{
public TreeEvents()
{
BaseTree.BeforeNodeRender += BaseTree_BeforeNodeRender;
}
void BaseTree_BeforeNodeRender(
ref XmlTree sender, ref XmlTreeNode node, EventArgs e)
{
if (node.NodeType == "content")
{
var content = new Content(int.Parse(node.NodeID));
if (content.ContentType.Alias == "Meeting")
{
var startDate = content.getProperty("meetingStartDate")
.Value.ToString();
var date = DateTime.Parse(startDate);
node.Text = String.Format("{0:MM/dd/yyyy} {1}",
date,
node.Text
);
}
}
}
}
}