【问题标题】:Customize Current Navigation Via SharePoint API通过 SharePoint API 自定义当前导航
【发布时间】:2010-01-13 18:56:47
【问题描述】:

我需要使用 SharePoint API 在左侧当前导航栏中删除一些默认节点(即人员和组、站点)。谁能给我任何关于如何实现这一目标的指导?

谢谢,MagicAndi

【问题讨论】:

    标签: sharepoint api sharepoint-2007 navigation


    【解决方案1】:

    您的代码将如下所示:

    using (SPSite oSite= new SPSite("http://someurl/")){
        using (SPWeb oWeb = oSite.OpenWeb()){
            foreach (SPNavigationNode oNode in oWeb.Navigation.QuickLaunch)
            {
                if (oNode.Title == "Sites") {
                    oNode.Delete();
                }
            }    
        }
    }
    

    但请注意,不建议按标题查找项目 - 如果 web'b 区域设置不是英语,则情况会有所不同。因此,最好通过 ID 查找节点。在此处查看 ID - http://msdn.microsoft.com/en-us/library/dd587301(office.11).aspx

    【讨论】:

      【解决方案2】:

      根据天真的回答:

      public static void DeleteNavigationNodes(string p_sSiteUrl)
      {
          try
          {
              SPSecurity.RunWithElevatedPrivileges(delegate()
              {
                  using (SPSite site = new SPSite(p_sSiteUrl))
                  {
                      using (SPWeb web = site.OpenWeb())
                      {
                          PublishingWeb pubWeb = null;
                          if (PublishingWeb.IsPublishingWeb(web))
                          {
                              pubWeb = PublishingWeb.GetPublishingWeb(web);
      
                              foreach (SPNavigationNode node in pubWeb.CurrentNavigationNodes)
                              {
                                  if ((node.Id != 1003 ) && (node.Id != 1004 ))
                                  {
                                      node.Delete();
                                  }
                              }
      
                              pubWeb.Update();           
                          }
                      }
                  }
              });
          }
          catch (Exception ex)
          {
              // Log error
           }
      }
      

      这篇文章也很有用:

      【讨论】:

        猜你喜欢
        • 2011-02-05
        • 2011-01-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多