通过 SharePoint API 自定义当前导航

发布于 2024-08-18 06:55:16 字数 92 浏览 1 评论 0原文

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

谢谢,魔法安迪

I have a requirement to remove a number of the default nodes (i.e. People and Groups, Sites) in the left hand current navigation bar using the SharePoint API. Can anyone give me any guidance on how to achieve this?

Thanks, MagicAndi

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薄荷梦 2024-08-25 06:55:16

您的代码将如下所示:

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

Your code will look something like this:

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();
            }
        }    
    }
}

be aware, though, that finding the item by title is not very recommended - it will differ if the web'b locale is not English. So it would be a better idea to find the node by its ID. See IDs here - http://msdn.microsoft.com/en-us/library/dd587301(office.11).aspx

韵柒 2024-08-25 06:55:16

基于天真的回答:

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
     }
}

这篇文章也很有用:

Based on naivists's answer:

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
     }
}

This article was also useful:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文