开发者

How to get a sites nodes in the topnavbar in sharepoint 2010?

I have a site called MySite in this site I have a document library called Resources and two subsites called site1 and site2.

On MySite I have a top nav bar with links: MySite | Resources | Site1 | Site2

When I try to get the navigation nodes I only get one of them and that is Resources (I want to get site1 and site2 so that I can modify them). How can I get all nodes, regardless of if it's a document library or subsite?

Code I us开发者_如何学运维e:

SPNavigationNodeCollection topNavBar = parentID.Navigation.TopNavigationBar;
string nodes ="";
foreach (SPNavigationNode node in topNavBar)
{
nodes += node.Url.ToString();
}

label1.Text = nodes;

Why do I only get the Resources node?

EDIT I can add a proper link to the parent site with

newWeb.ParentWeb.Navigation.TopNavigationBar.AddAsLast(new SPNavigationNode(newSiteName, newSiteName + "/pages/home.aspx"));

this will now get me to the wiki and since subsites inherit navigation the link will be the same on them. However, with this I get two links to the wiki, one that's working with the code above and one that's broken so I try to delete that one in a similar way to how I add the correct one. I would hope that there would be a more convenient way of doing it though.


I think the Resources | Site1 | Site2 are the site collections. To get all the site collection using following code:

SPSite site = new SPSite("siteURL");
SPWeb web = site.OpenWeb();
SPSiteCollection coll = web.webs;

You get all the site collection Resources, Site1, Site2.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜