I have following code

var subWeb = newWeb.Webs.Add(subsite.Url, subsite.Title, subsite.Title, 1033, PublishTemplate, false, false);
subWeb.AllowUnsafeUpdates = true;
PublishingWeb publiSubWeb = PublishingWeb.GetPublishingWeb(subWeb);
publiSubWeb.Navigation.InheritGlobal = true;
publiSubWeb.Navigation.GlobalIncludeSubSites = true;
publiSubWeb.Navigation.GlobalIncludePages = true; // <-- Does not work 
publiSubWeb.Navigation.CurrentIncludePages = true; // <-- Does  not work
publiSubWeb.Navigation.CurrentIncludeSubSites = true;
publiSubWeb.Navigation.SortAscending = false;

But it seems that the navigation properties "GlobalIncludePages" en "CurrentIncludePages" are not working. When I browse to the Navigation site (Site Settings) the "Show Pages" in the Current & Global Navigation is still unchecked... Also the property "ShowSiblings" (in other code by me) does not work.

I already put AllowUnsafeUpdates and some extra web updates in my code; but also this does not help.

I am using a sandboxed solution. When I execute the same code in a console application it works. Strange. Is this really a limit of the sandbox???

Any ideas?


  • Seems that none of the properties can be set. So it does not work at all...
    – Davy
    Jun 14, 2012 at 15:15
  • I am using a sandboxed solution. When I execute the same code in a console application it works. Strange. Is this really a limit of the sandbox???
    – Davy
    Jun 14, 2012 at 15:16
  • Hi @Davy. I'm also working on a sandbox solution and need to initialise the navigation settings on my publishign sites. Did you ever find a workaround?
    – user4545
    Aug 9, 2012 at 6:25
  • Nick, i am sorry but i never found a solution to do it in sandbox.
    – Davy
    Aug 9, 2012 at 13:20

3 Answers 3


I managed to solve this one today.

@Vardhaman is correct: the Microsoft.SharePoint.Publishing.dll assembly simply isn't sandbox compatible -- so none of the methods or properties in this assembly will work (even though Visual Studio doesn't throw any warnings or errors at compile-time!). If you reflect this assembly though, you can see that the navigation settings are really just stored as simple property bag values on the SPWeb object. This is the list of property bag keys that control the navigation settings internally, they're all self-explanatory:

    // Common (applies to both global and current navigation):
    public const string IncludeSubsitesKey = "__IncludeSubSitesInNavigation";
    public const string IncludePagesKey = "__IncludePagesInNavigation";

    // Global navigation:
    public const string GlobalNavigationDynamicChildLimitKey = "__GlobalDynamicChildLimit";

    // Current navigation:
    public const string CurrentNavigationInheritKey = "__InheritCurrentNavigation";
    public const string CurrentNavigationShowSiblingsKey = "__NavigationShowSiblings";
    public const string CurrentNavigationOrderingMethodKey = "__NavigationOrderingMethod";
    public const string CurrentNavigationAutomaticSortingMethodKey = "__NavigationAutomaticSortingMethod";
    public const string CurrentNavigationSortAscendingKey = "__NavigationSortAscending";
    public const string CurrentNavigationDynamicChildLimitKey = "__CurrentDynamicChildLimit";

The great news is that you can simply add these keys to the property bag yourself in order to achieve the same result as setting the properties in the Microsoft.SharePoint.Publishing.Navigation class. See below for an example:

    if (web.GetProperty(CurrentNavigationInheritKey) != null)

    web.AddProperty(CurrentNavigationInheritKey, bool.FalseString);

Note: Another undocumented bizzarre quirk of the sandbox is that the property bag can only be manipulated using the following methods:

    SPWeb.AddProperty(key, value)
    SPWeb.SetProperty(key, value)

The following alternate methods of accessing the property bag will only work in a non-sandboxed solution. Interestly, exceptions aren't thrown at runtime if you use these methods, however null values will always be returned and new values will simply never be persisted... So don't use them!

    SPWeb.AllProperties[key, value]
    SPWeb.Properties[key, value]
  • That's Awesome! In Sandbox, we have to think of novel ways like this to achieve simple tasks :) Aug 10, 2012 at 18:12
  • One more thing to add... If you create your subsite using a custom WebTemplate instead, then you can configure the navigation by simply passing in the appropriate feature properties. See below: <!-- Per-Web Portal Navigation Properties --> <Feature ID="541F5F57-C847-4e16-B59A-B31E90E6F9EA"> <Properties xmlns="http://schemas.microsoft.com/sharepoint/"> <Property Key="ShowSiblings" Value="false" /> <Property Key="IncludeSubSites" Value="true" /> <Property Key="IncludePages" Value="false" /> </Properties> </Feature> I can confirm that this works in a sandbox solution.
    – user4545
    Aug 14, 2012 at 7:30
  • Nice post was able to fix CurrentDynamicChildLimit & GlobalDynamicChildLimit values. How was you able to find the key ?? e.g. "__GlobalDynamicChildLimit" & "__CurrentDynamicChildLimit";
    – Saroj Jha
    May 26, 2015 at 8:13

Though this thread is already marked as answer, still would like to add more to it. As mentioned above,"_IncludeSubsitesInNavigation" and "_IncludePagesInNavigation" properties can be added to the SPWeb property bag and made to work in sandbox scenario. Now these two properties are common for global as well as current navigation. For a scenario where we would like different values for these properties for global and current navigation, this will not work. However there are properties like "_GlobalNavigationIncludeTypes" and "_CurrentNavigationIncludeTypes" that comes to the rescue in such a situation. I have written a detailed blog on both these properties. Anybody facing a similar issue can have a look for the reference


Cheers, Geetanjali


The PublishingWeb class is a part of the Microsoft.SharePoint.Publishing library. This library is not allowed in the Sandbox. Instead of Microsoft.SharePoint.Publishing.PublishingWeb.Navigation, you can try using the Microsoft.SharePoint.Navigation class which is allowed in the sandbox.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.