0

我试图在sharepoint中返回一组导航节点的所有子节点,SDK暗示我应该做这样的事情:

NodeColl = objSite.Navigation.TopNavigationBar 
Dim Node as SPNavigationNode

For Each Node In NodeColl
  if Node.IsVisible then
    Response.Write("<siteMapNode url=""" & Node.Url & """ title=""" & Node.Title & """  description=""" & Node.Title & """ >" & Environment.NewLine)
    Dim SubChildNodes as SPNavigationNodeCollection = Node.Children
    Response.Write(SubChildNodes.Count) 'returns 0 always even though I know theres over 20 nodes in some of the sections
    Dim ChildNode as SPNavigationNode
    For Each ChildNode in SubChildNodes
      if ChildNode.IsVisible then
        Response.Write("<siteMapNode url=""" & ChildNode.Url & """ title=""" & ChildNode.Title & """  description=""" & ChildNode.Title & """ />" & Environment.NewLine)
      End if
    Next
    Response.Write("</siteMapNode>" & Environment.NewLine)
  End If
Next

但是,每当我这样做时,它都会列出顶级导航节点,但我无法显示子项。

4

2 回答 2

0

我有同样的问题,我找到了解决方案

using (SPSite site = new SPSite("http://server"))
{
    using (SPWeb web = site.OpenWeb())
    {
        SPNavigationNode quicklaunch = web.Navigation.GetNodeById(1025);
        if (quicklaunch != null)
        {
            foreach (SPNavigationNode heading in quicklaunch.Children)
            {
                PrintNode(heading);
            }
        }
    }
}

static void PrintNode(SPNavigationNode node)
{
    foreach (SPNavigationNode item in node.Children)
        PrintNode(item);
}

确保您有一个SiteMapDataSource与您的母版页关联的快速启动。

于 2011-01-07T07:15:32.997 回答
0

我遇到了同样的问题:我试图SPWeb.Navigation.Quicklaunch从从 onet.xml 激活的网络范围功能的功能接收器SPWeb.Navigation.QuickLaunch.Count中访问.xml。

我的解决方案是在我的功能接收器中打开一个新的 SPSite 和一个新的 SPWeb,之后我就可以访问快速启动项。例如,这对我有用:

using (SPSite site = new SPSite("http://yourserver/"))
{
  using (SPweb web = site.OpenWeb("theweb"))
  {
    web.Navigation.QuickLaunch.Count ; // greater than zero

    // manipulate your quick launch here
  }
}

我假设这是因为创建新的 SPWeb 对象会从数据库加载网络的最新状态,而传递给我的功能接收器的 SPWeb 并不代表最新状态。但这是我猜

于 2012-04-03T05:35:35.213 回答