Pergunta

I have custom sharepoint site xml template.

sharepoint when i am creating custom site based on my site template. Features included:

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

And i have feature where i am trying to add nodes:

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

Before add i am removing everything:

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

Problem that after site is created i have not only my link but also "Sites" and "Lists"! But i dont want to have those! Please advice how to remove them!

Foi útil?

Solução

the foreach loop is buggy. Use:

  for(int i = quicklaunchCollection.Count - 1; i >= 0; i--)
  {
     quicklaunchCollection[i].Delete();
  }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top