I am working on a more complex class that will have an option to return deep Hierarchy and will have different options like get Hierierchy for only 2 level deep channels etc. Mean while I wanted to put the simplest solution to get the list with Display Name and Url for new comers to MCMS ...to keep it completely simple I am not including any Error handling which you should including your code ...
For this example lets assume you have you left Navigation defined in SiteManager as follows Channel the Root Channel of MCMS, MySite is the Name of your website, en-CA is you are localizing you website then usually you will have english french etc channel, LeftNavigation a Channel name that contains underneath all the channels that represent the Options that will be displayed in Left Navigation.
I will display the list in simple Anchor tag separated by BR
using Microsoft.ContentManagement.Publishing;
using System.Text;
private CmsHttpContext ctx = CmsHttpContext.Current;
Channel startingChannel = (Channel)ctx.Searches.GetByPath(“/Channels/MySite/en-CA/LeftNavigation“);
StringBuilder sb = new StringBuilder();
foreach(Channel ch in startingChannel.Channels)
{
sb.Append(“<a href='“);
sb.Append(ch.Url);
sb.Append(“'>“);
sb.Append(ch.DisplayName);
sb.Append(“</a><BR>“);
}
Now you can do sb.ToString() to get the HTML to display the Left Navigation anchor menu.
Off course you can use it for TopNavigation or some other similar functionality.