I am having a three site collection along with subsite in a same webapplication as below
SiteCollection1
SubSite1.1
SubSIte1.2
SiteCollection2
SubSite2.1
SubSIte2.2
We have the requirment to create a custom navigation provider and point all sitecollection in a single menu control and each will have similer global menu as below. We don't want to go for HardCoded/SiteMap file as in our requirment whenever any new subsite added in sitecollection should reflect at same time.
SiteCollection1 SiteCollection2 //on mouse hower subsite will display
I am using below code to genrate the same but my funcation GetSiteMap not able to read sitecollection2 PortalSiteMapProvider value from sitecollection1. while i change the line childNodeB.ChildNodes = testchildNodeSiteB; with childNodeB.ChildNodes = nodeColl; it work fine and populate the value for current site.
enter code here
public override SiteMapNodeCollection GetChildNodes(System.Web.SiteMapNode node)
{
string url1 = "http://dev:111"; //this is current site collection
string url2 = "http://dev:111/sites/Sitecollection2";
PortalSiteMapNode pNode = node as PortalSiteMapNode;
if (pNode != null)
{
if (pNode.Type == NodeTypes.Area)
{
SiteMapNodeCollection nodeColl = base.GetChildNodes(pNode);
SiteMapNodeCollection test = new SiteMapNodeCollection();
SiteMapNode childNode2 = new SiteMapNode(this, url2, url2, "SiteCollection2");
nodeColl.Add(childNode2);
SiteMapNodeCollection testchildNodeSite2 = GetSiteMap(url2);
***childNode2.ChildNodes = testchildNodeSite2;***
return nodeColl;
}
else
return base.GetChildNodes(pNode);
}
else
return new SiteMapNodeCollection();
}
public SiteMapNodeCollection GetSiteMap(string url)
{
//using (SPWeb oWeb = SPContext.Current.Site.OpenWeb(guidWebsite))
using (SPWeb spweb = SPContext.Current.Site.AllWebs[url])//new SPSite(url))
{
SPSite site = spweb.Site;
SiteMapNodeCollection headingNodes = new SiteMapNodeCollection();
headingNodes = null;
PortalSiteMapProvider portalProvider = PortalSiteMapProvider.CurrentNavSiteMapProviderNoEncode;
// Look up the node for the given Web site URL.
PortalWebSiteMapNode webNode = portalProvider.FindSiteMapNode(url) as PortalWebSiteMapNode;
if (webNode != null)
{
headingNodes = portalProvider.GetChildNodes(webNode, NodeTypes.Heading, NodeTypes.None);
}
return headingNodes;
}
}
enter code here
Please suggest your views, how to read SiteMapNodeCollection of SiteCollection2 from SiteCollection1.