2008-11-12 68 views
0

我试图返回一组在SharePoint导航节点的所有子节点,该SDK意味着我应该做这样的事情:MOSS SpNavigationNode.Children总是空

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 

但是每当我做,它列出了顶级导航节点,但我无法让孩子显示。

回答

0

我正面临同样的问题:我试图访问从onet.xml激活的web作用域功能的接收器SPWeb.Navigation.Quicklaunch,但SPWeb.Navigation.QuickLaunch.Count始终为0,尽管我已经在其他功能中明确添加了列表实例之前在相同的onet.xml中激活。

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

​​

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

+0

原来isVisible属性总是错误的... – Mauro 2012-08-01 14:28:26

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