To implement your own site map provider in SharePoint 2010.
public class CustomSiteMapProvider :
SiteMapProvider
{
SiteMapNode rootNode = null;
public
CustomSiteMapProvider() {}
public override void Initialize(string
name.System.Collections.Specialized.NameValueCollection
attributes)
{
// Initialize static
siteMap
this.rootNode = new SiteMapNode(this, "rootNode",
"/default.aspx", "Home");
this.rootNode.ChildNodes.Add(new
SiteMapNode(this, "childNode1","/page1", "SubPage
1"));
this.rootNode.ChildNodes.Add(new SiteMapNode(this,
"childNode2","/page2", "SubPage 2"));
}
public override
SiteMapNode FindSiteMapNode(string rawUrl)
{
switch
(rawUrl)
{
case "/default.aspx": return
this.rootNode;
case "/page1.aspx": return
this.rootNode.ChildNodes[0];
case "/page2.aspx": return
this.rootNode.ChildNodes[1];
default: return
null;
}
}
public override SiteMapNodeCollection
GetChildNodes(SiteMapNode node)
{
SiteMapNodeCollection
children = new SiteMapNodeCollection();
if (node != null &&
node.HasChildNodes)
{
foreach (SiteMapNode cNode in
node.ChildNodes) children.Add(cNode);
}
return
children;
}
public override SiteMapNode
GetParentNode(SiteMapNode node)
{
return (node == null) ? null
: node.ParentNode;
}
protected override SiteMapNode
GetRootNodeCore()
{
return
rootNode;
}
}
No comments:
Post a Comment