Posts mit dem Label programmatically werden angezeigt. Alle Posts anzeigen
Posts mit dem Label programmatically werden angezeigt. Alle Posts anzeigen

Mittwoch, 13. Februar 2013

Change from Managed to Structural Navigation in SharePoint 2013 publishing programmatically


I developped a WebTemplate based on a Publishing site definition. The publishing features activated Managed Navigation by default. And I was unable to find how to change it programmatically. Then I used SharePoint Manager 2013 and found in the web Properties following key: SPFeatureProperty
And this was the Value:
<?xml version="1.0" encoding="utf-16" standalone="yes"?>
<WebNavigationSettings Version="1.1">
  <SiteMapProviderSettings>
    <SwitchableSiteMapProviderSettings Name="CurrentNavigationSwitchableProvider" UseParentSiteMap="True" />
    <TaxonomySiteMapProviderSettings Name="CurrentNavigationTaxonomyProvider" UseParentSiteMap="True" />
    <SwitchableSiteMapProviderSettings Name="GlobalNavigationSwitchableProvider" UseParentSiteMap="True" />
    <TaxonomySiteMapProviderSettings Name="GlobalNavigationTaxonomyProvider" UseParentSiteMap="True" />
  </SiteMapProviderSettings>
<NewPageSettings AddNewPagesToNavigation="True" CreateFriendlyUrlsForNewPages="True"/>
</WebNavigationSettings>

I Compared it tot he value of a second web I configured through the SiteSetting interface:
<?xml version="1.0" encoding="utf-16" standalone="yes"?>
<WebNavigationSettings Version="1.1">
  <SiteMapProviderSettings>
    <SwitchableSiteMapProviderSettings Name="CurrentNavigationSwitchableProvider" TargetProviderName="CurrentNavigation" />
    <TaxonomySiteMapProviderSettings Name="CurrentNavigationTaxonomyProvider" Disabled="True" />
    <SwitchableSiteMapProviderSettings Name="GlobalNavigationSwitchableProvider" UseParentSiteMap="True" />
    <TaxonomySiteMapProviderSettings Name="GlobalNavigationTaxonomyProvider" UseParentSiteMap="True" />
  </SiteMapProviderSettings>
  <NewPageSettings AddNewPagesToNavigation="True" CreateFriendlyUrlsForNewPages="True"/>
</WebNavigationSettings>

So I started looking for the WebNavigationSettings Class and I found this Post: Working with publishing navigation in SharePoint 2013
Here ist the code like it should be in a feature receiver:
SPWeb web = (SPWeb)properties.Feature.Parent;
myNavigationSettings.CurrentNavigation.Source = StandardNavigationSource.PortalProvider;
myNavigationSettings.Update();

StandardNavigationSource is an enumeration and looks like this:
public enum StandardNavigationSource
    {
        Unknown = 0,
        PortalProvider = 1,
        TaxonomyProvider = 2,
        InheritFromParentWeb = 3,
    }