Building a Site Map with Recursive Navigation

In traditional Web site development, the developer controlled navigation. This model worked pretty well, since they also controlled content contribution. However, after you've implemented CMS, the business users really control the site. More to the point, even if the developers wanted to maintain navigation manually, it's almost impossible to keep up with even a modestly sized contributor group. As a result, developers must create a mechanism that can effectively react to a site without inherently knowing what the structure of that site is. This is especially apparent when we are talking about a site map. To this end, CMS provides two mechanisms for allowing developers to create code that can elegantly and effectively react to an ever changing site structure: the Publishing API (PAPI) and Site Manager.

To begin, Site Manager allows developers and content contributors to create a structure that defines the organization of their site in the form of channels. This channel structure is easily defined through Site Manager and through the constant contribution of postings within CMS. Then, the Publishing API provides the ability to access that structure, exposing properties like URL, Display Name, and Name in addition to an unlimited number of custom properties. Once you have a structure and a way to access it, programmatic recursion of that structure allows developers to be freed from the bonds of having to know the structure up front. To illustrate this point, let's examine the BOTS Consulting site map.

In Figure 36-1 you'll see a picture of Site Manager, exposing the channel structure of the BOTS Web site. Be careful to note the channels and the structure.

Figure 36-1. In Site Manager you can see the channel structure for BOTS

graphics/36fig01.gif

Now, let's look at the actual site map in the site. In Figure 36-2 you'll notice that all the channels defined in Site Manager are exposed in the site map page. In this case the BOTS IT department decided that they only wanted to expose the sections of the site (the channels) and not the actual pages. It's relatively trivial to include postings as well; just keep in mind that it may affect performance since you're exposing many more objects.

Figure 36-2. The BOTS Consulting site map

graphics/36fig02.jpg

In Listing 36-1 you can see our site map function. In this function, we're adding literal and HtmlAnchor controls to a .NET placeholder control we've embedded in our user control.

Listing 36-1 A sample recursive site map control
 public void BuildSiteMap(Channel startChannel) {       // Add an unordered list tag to our .NET placeholder control       this.SiteMap.Controls.Add(new LiteralControl("<UL>"));       // Create a new link and assign the appropriate values from the channel       // startChannel object.       HtmlAnchor navigationLink = new HtmlAnchor();       navigationLink.InnerText = startChannel.DisplayName;       navigationLink.HRef = startChannel.Url;       navigationLink.Attributes.Add("style","FONT-WEIGHT: bold; COLOR: gray");       // Add the new link to our .NET placeholder control       this.SiteMap.Controls.Add(new LiteralControl("<LI>"));       this.SiteMap.Controls.Add(navigationLink);       this.SiteMap.Controls.Add(new LiteralControl("</LI>"));       // Get a collection of channels in the current channel       ChannelCollection subChannels = startChannel.Channels;       // Make sure that we got a collection       if (subChannels != null)       {             // Call our BuildSiteMap function for each of the subchannels             foreach(Channel subChannel in subChannels)             {                   this.BuildSiteMap(subChannel);             }       }       // Close the unordered list tag and add it to our .NET placeholder control       this.SiteMap.Controls.Add(new LiteralControl("</UL>")); } 

In this example, we accept one parameter, which is the starting point for the site map. From there we recursively traverse our tree structure, "discovering" all the channels in our site. We've hardcoded how the site map displays (a large unordered list), but this can certainly be expanded to include formatting as a parameter.



Microsoft Content Management Server 2002. A Complete Guide
Microsoft Content Management Server 2002: A Complete Guide
ISBN: 0321194446
EAN: 2147483647
Year: 2003
Pages: 298

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net