Customizing Navigation Controls and Providers Sunday, Aug 17 2008 

To customize navigation, you should rely on the ASP.NET Site Navigation mechanism, because it provides a standard, consistent, and easily managed solution.
Customizing Web Display Controls (Menu, TreeView, and SiteMapPath) :
You can customize the look and feel of standard display controls by using cascading style sheets (CSSs). You can also write your own ASP.NET 2.0 controls and use them in Office SharePoint Server 2007 navigation. To learn more, see the Menu class documentation.

Note: Office SharePoint Server 2007 also provides default navigation components that you can customize, such as the Content By Query Web Part and the Table of Contents Web Part. You can configure these two controls to present a custom selection of links.

To implement your own site map provider, you can derive a custom provider class from any of the default site map providers. Office SharePoint Server 2007 includes several default providers. You can also derive a custom provider class from the SiteMapProvider class in the System.Web namespace. However, deriving the Office SharePoint Server 2007 site map providers supplies several additional benefits such as navigation node caching and security trimming. Therefore, you should use the Office SharePoint Server 2007 caching and security trimming infrastructure instead of writing your own caching and security trimming in a custom provider by deriving from the default providers. Although the site map provider classes have approximately twenty abstract or virtual methods, only a small number must be overridden and implemented in a custom site map provider. The following code example derives from the PortalSiteMapProvider class and demonstrates how to add items to the site map provider.

public class CustomNavProviderWithList : PortalSiteMapProvider {
public override SiteMapNodeCollection

GetChildNodes(System.Web.SiteMapNode node) {
PortalSiteMapNode portalNode = node as PortalSiteMapNode;
if (portalNode != null)
{
if (portalNode.Type == NodeTypes.Area)
{ SiteMapNodeCollection nodeColl = base.GetChildNodes(portalNode);
using (SPSite currentSite = new SPSite(portalNode.Url))
{ SPWeb currentWeb = currentSite.OpenWeb();
SPListCollection lists = currentWeb.Lists;
foreach (SPList list in lists)
{ string listUrl = list.DefaultViewUrl;
PortalSiteMapNode childNode =
new PortalSiteMapNode(webNode,
listUrl, NodeTypes.custom, list.Title, listUrl, null);
nodeColl.Add(childNode);
} }
return nodeColl;
} else { return base.GetChildNodes(portalNode);
} }
else { return new SiteMapNodeCollection(); } } }

Cheers…

PortalSiteMapProvider Saturday, Aug 16 2008 

The PortalSiteMapProvider object is the true source of hierarchical navigation data and it provides the data to the PortalSiteMapDataSource object. The PortalSiteMapProvider retrieves nodes from the Windows SharePoint Services 3.0 SPNavigation store. You use the SPNavigation object to create static links and groupings. After you provide static links and groupings, the application merges in dynamic items that represent Web sites and pages with the static links and groupings. Office SharePoint Server 2007 also applies security trimming so that users see only the navigation items to which they have permission to navigate.
Declare named providers in the application’s web.config file to make them widely accessible. Declarations of the two most important PortalSiteMapProvider objects—
CombinedNavSiteMapProvider and CurrentSiteNavSiteMapProvider—are shown in the following code.

<add name=”CombinedNavSiteMapProvider” description=

“MOSS 2007 provider for Combined navigation” Type=”Microsoft.SharePoint.Publishing.
Navigation.PortalSiteMapProvider”
NavigationType=”Combined” EncodeOutput=”true”>
<add name=”CurrentNavSiteMapProvider” description=
“MOSS 2007 provider for Current navigation” Type=
“Microsoft.SharePoint.Publishing.
Navigation.PortalSiteMapProvider”
NavigationType=”Current” EncodeOutput=”true”/>
Note : The name of the first provider, CombinedNavSiteMapProvider, matches the value specified for the SiteMapProvider property. This indicates that a Horizontal menu will be created.
The following are the properties,
  1. NavigationType – Gets or sets the type of navigation for this navigation provider. Available options include “Combined”, “Current”, and “Global” and behave as specified by the next three properties: CombinedNavSiteMapProvider, CurrentSiteMapProvider, and CurrentSiteNavSiteMapProviderNoEncode.
  2. CombinedNavSiteMapProvider – Gets the PortalSiteMapProvider object that is attached by default to the global navigation menu.
  3. CurrentSiteNavSiteMapProvider – Gets the PortalSiteMapProvider object that is attached by default to the current navigation menu or the QuickLaunch toolbar.
  4. CurrentSiteNavSiteMapProviderNoEncode – Gets the PortalSiteMapProvider object that is attached by default to the breadcrumb navigation.
    Declare this property almost identically to CurrentSiteNavSiteMapProvider, but exclude the EncodeOutput=”true” attribute.
  5. GlobalNavSiteMapProvider – Gets a PortalSiteMapProvider object with the NavigationType property set to Global.
  6. EncodeOutput – Gets or sets whether to HTML-encode the Title property of any PortalSiteMapNode object returned by the provider.The ASP.NET 2.0 menu control does not automatically HTML-encode the Title property when rendering. However, the ASP.NET 2.0 SiteMapPath control does HTML-encode the Title property.
  7. DynamicChildLimit – Gets or sets the number of dynamic child items to show at each level. Dynamic child items can be subsites (any SPWeb objects) and pages.
  8. RequireUniqueKeysForNodes – Gets or sets whether nodes returned from the provider should each have unique values for their Key properties.
    To enable menu highlighting to work correctly on authored links and headings, set RequireUniqueKeysForNodes=”false”. This does not cause problems when attaching to an ASP.NET 2.0 menu control through a data source, but for most other display controls, declare RequireUniqueKeysForNodes=”true”.
  9. IncludeSubSites – Gets or sets whether this provider returns subsites.

Cheers…

PortalSiteMapDataSource Saturday, Aug 16 2008 

The PortalSiteMapDataSource is a data source specific to Office SharePoint Server 2007 that retrieves data from the PortalSiteMapProvider object and exposes data according to the ASP.NET 2.0 hierarchical data source interface. The PortalSiteMapDataSource object specifies the name of the PortalSiteMapProvider object it uses to retrieve data through the ASP.NET 2.0 SiteMapProvider property.
When the master page markup includes the DataSourceID=”GlobalNavDataSource” attribute, the application returns a PortalSiteMapDataSource object.

<PublishingNavigation:PortalSiteMapDataSource ID=”GlobalNavDataSource” Runat=”server” SiteMapProvider=”CombinedNavSiteMapProvider” ShowStartingNode=”false” StartFromCurrentNode=”true” StartingNodeOffset=”0″ TrimNonCurrentTypes=”Heading” TreatStartingNodeAsCurrent=”true”/>

The properties are,

  1. ShowStartingNode – Affects whether the starting node is returned by the data source.When this property is set to true, the data source returns the starting node. The menu receives the starting node, which can be the root node, and items below the starting node.When this property is set to false, the data source does not return the starting node. The menu receives only the items below the starting node.
  2. StartFromCurrentNode – Affects where the data source starts. That is, this property sets which section of the overall site hierarchy the data source control returns to the menu.When this property is set to true, Office SharePoint Server 2007 instructs the PortalSiteMapDataSource object to apply its rules for determining where it should be starting.
  3. StartingNodeOffset – Gets or sets a positive or negative integer offset from the starting node that determines the top-level site hierarchy that is exposed by the DataSourceControl object.The default is 0, which indicates that the top-level site hierarchy exposed by the SiteMapDataSource object is the same as the starting node.The effect of this property is variable, undefined, and depends on site hierarchy details that are out of scope for this topic.
  4. TrimNonCurrentTypes – Allows context-based and type-based node trimming.
    In this example, TrimNonCurrentTypes=”Heading”, which instructs the data source to remove any nodes of type Heading that are not directly below the current node.
    You can specify multiple values for this property in a comma-delimited list. Available values are defined in the
    NodeTypes enumeration.
  5. TrimNonAncestorTypes – Trims any specified types that are not directly below the current site or one of its ancestors.
  6. TrimNonAncestorDescendantTypes – Trims any nodes of specified types that are not below the current site or one of its ancestor or descendant sites.
  7. TreatStartingNodeAsCurrent – Affects which node is treated as the current node for trimming purposes. By default, current node refers to the node representing the item that is currently being visited.When TreatStartingNodeAsCurrent is set to true, the starting node of the data source is treated as the context or trimming node.

Cheers…