MOSS 2007: Implementing a custom Navigation

You can use the following code snippet to iterate through your navigation tree recursive:

using Microsoft.SharePoint;
using Microsoft.SharePoint.Publishing.Navigation;

public class SiteMapTest : System.Web.UI.WebControls.WebParts.WebPart
{

   protected
override void RenderContents(System.Web.UI.HtmlTextWriter writer)
   {
      PortalSiteMapProvider map = new PortalSiteMapProvider();
      writer.Write("<table>");
      this.PrintTree(map.RootNode, writer, 0);
      writer.Write("</table>");
   }

   public
void PrintTree(SiteMapNode node, System.Web.UI.HtmlTextWriter writer, int level)
   {
      string space = string.Empty;
      for (int i = 0; i < level; i++)
      {
         space += "&nbsp;&nbsp;&nbsp"&nbsp;&nbsp;&nbsp";
      }
      writer.Write("<tr><td>" + space + "<a href=\"" + node.Url + "\">" + node.Title + "</a></tr></td>");
      foreach (SiteMapNode childNode in node.ChildNodes)
      {
         PrintTree(childNode, writer, level + 1);
      }
   }

}

If you use a SPSiteMapProvider instead of PortalSiteMapProvider, you will only see your sites, no pages.
SPContentMapProvider delivers nothing for me, there are no ChildNodes defined. I didn't check out SPNavigationProvider, but I had some bad expierence with Microsoft.SharePoint.Navigation.SPNavigation.
For some more informations see: http://msdn2.microsoft.com/en-us/library/aa830815.aspx#Office2007SSBrandingWCMPart2_CustomizingNavigation

posted on 2007-04-28 21:41  an_andy  阅读(834)  评论(0编辑  收藏  举报

导航