如何从快速启动菜单中删除“列表”和“站点”节点?

时间:2012-08-20 10:30:01

标签: sharepoint sharepoint-2010 sharepoint-api

我有自定义sharepoint网站xml模板。

当我根据我的网站模板创建自定义网站时,

sharepoint。 功能包括:

 <Feature ID="22A9EF51-737B-4ff2-9346-694633FE4416">
      <!-- Publishing -->
      <Properties xmlns="http://schemas.microsoft.com/sharepoint/">
        <!--<Property Key="ChromeMasterUrl" Value="~SiteCollection/_catalogs/masterpage/my.master" />-->
        <Property Key="WelcomePageUrl" Value="$Resources:osrvcore,List_Pages_UrlName;/default.aspx" />
        <Property Key="PagesListUrl" Value="" />
        <Property Key="SimplePublishing" Value="true" />
        <!--<Property Key="DefaultPageLayout" Value="~SiteCollection/_catalogs/masterpage/my.aspx"/>-->
        <Property Key="EnableApprovalWorkflowOnDocuments" Value="false"/>
        <Property Key="EnableApprovalWorkflowOnImages" Value="false"/>
        <Property Key="EnableApprovalWorkflowOnPages" Value="false"/>
        <Property Key="EnableModerationOnDocuments" Value="false"/>
        <Property Key="EnableModerationOnImages" Value="false"/>
        <Property Key="EnableModerationOnPages" Value="true"/>
        <Property Key="EnableSchedulingOnDocuments" Value="false"/>
        <Property Key="EnableSchedulingOnImages" Value="false"/>
        <Property Key="EnableSchedulingOnPages" Value="true"/>
        <Property Key="RequireCheckoutOnDocuments" Value="false"/>
        <Property Key="RequireCheckoutOnImages" Value="false"/>
        <Property Key="RequireCheckoutOnPages" Value="false"/>
        <Property Key="VersioningOnPages" Value="MajorAndMinor"/>
      </Properties>
    </Feature>

    <Feature ID="541F5F57-C847-4e16-B59A-B31E90E6F9EA">
      <!-- Per-Web Portal Navigation Properties-->
      <Properties xmlns="http://schemas.microsoft.com/sharepoint/">
        <Property Key="InheritGlobalNavigation" Value="false"/>
        <Property Key="IncludeSubSites" Value="false"/>
        <Property Key="IncludePages" Value="false"/>
      </Properties>
    </Feature>

我有功能,我正在尝试添加节点:

   private void ProvisionQuickLaunchLinks(SPWeb web)
    {
        var serverUrl = web.ServerRelativeUrl;
        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            using (SPSite impSite = new SPSite(web.Site.ID))
            {
                RemoveExistingNodes(web, impSite);

                using (SPWeb impWeb = impSite.OpenWeb(web.ID))
                {
                    if (impWeb != null && impWeb.Exists)
                    {
                        try
                        {
                            var isRoot = SiteHelper.GetIsProjectRootSite(web);
                            impWeb.AllowUnsafeUpdates = true;

                           AddQuickLink(impWeb, "My link", "/Lists/MyList/Forms/AllItems.aspx", Constants.Navigation.NavigationLinkKey, "/_layouts/temp/temp/img/menu_icon3.png");
                            impWeb.Update();
                        }

                        catch (Exception ex)
                        {
                            LoggingService.WriteError(ex, "Cannot remove links to navigation menu");
                        }
                        finally
                        {
                            if (impWeb != null)
                            {
                                impWeb.AllowUnsafeUpdates = false;
                            }
                        }
                    }
                }
            }
        });
    }

在添加之前我将删除所有内容:

private static void RemoveExistingNodes(SPWeb web, SPSite impSite)
    {
        using (SPWeb impWeb = impSite.OpenWeb(web.ID))
        {
            if (impWeb != null && impWeb.Exists)
            {
                try
                {
                    var isRoot = SiteHelper.GetIsProjectRootSite(web);
                    impWeb.AllowUnsafeUpdates = true;

                    var quicklaunchCollection = impWeb.Navigation.QuickLaunch;
                    foreach (SPNavigationNode tempNode in quicklaunchCollection)
                    {
                        impWeb.Navigation.QuickLaunch.Delete(tempNode);
                        impWeb.Update();
                    }
                }
                catch (Exception ex)
                {
                    LoggingService.WriteError(ex, "Cannot remove links to navigation menu");
                }
                finally
                {
                    if (impWeb != null)
                    {
                        impWeb.AllowUnsafeUpdates = false;
                    }
                }
            }
        }
    }

创建网站后,我不仅有我的链接,还有“网站”和“列表”! 但我不想拥有那些!请建议如何删除它们!

1 个答案:

答案 0 :(得分:2)

foreach循环是错误的。使用:

  for(int i = quicklaunchCollection.Count - 1; i >= 0; i--)
  {
     quicklaunchCollection[i].Delete();
  }