I am trying to delete all the top navigation items from a console application, and add headers/sub items to the top navigation. I am also trying to uncheck the options to show subsites and show pages.

I found few articles talking about this, they suggest doing something like this:

  using(var ctx = new ClientContext("url"))
            var web = ctx.Web;
            web.AllProperties["__GlobalNavigationIncludeTypes"] = "1";


This isn't working for me, I can't uncheck the show pages or show subsites option.

What I need to do is to clear the top navigation, then start adding links and headers. How do I achieve that from a console application?



You should be aware of Microsoft.SharePoint.Client.Publishing and Microsoft.SharePoint.Client.Publishing.Navigation namespaces in CSOM API is not supported to modify navigation settings. for more details check Access and Manipulate Navigation Settings via SharePoint Client Object Model

Now you have two option to achieve that

  1. Use CSOM by using ClientPortalNavigation.cs

  2. You have mentioned you are using console application so why you don't try to use SSOM rather than CSOM ! using SSOM you can achieve this easily and also you can find more resource about this

Below is a code via SSOM C# to achieve your goal.


// Web Navigation
using (var site = new SPSite("http://somesite"))
using (var web= site.OpenWeb())
 var navigation = web.Navigation;

// PublishingWeb Navigation
var pubWeb = PublishingWeb.GetPublishingWeb(web);

// WebNavigationSettings
var webNavigationSettings = new WebNavigationSettings(web);

To uncheck the show pages or show subsites option.

pubWeb.Navigation.CurrentIncludeSubSites = false;
pubWeb.Navigation.CurrentIncludePages = false;
pubWeb.Navigation.CurrentDynamicChildLimit = 20;

To clear links from the Site's Navigation for each via this code

SPWeb site = SPContext.Current.Web;
int id = int.Parse(topNavTreeView.SelectedNode.Value);
SPNavigationNode node = site.Navigation.GetNodeById(id);

For more details check

|improve this answer|||||
  • 2
    Thanks, useful hints. Regarding option 2, you ask, if the asker is to create a console application, why he does not use the SSOM. I can only assume, but probably the console application should run remotely. Just using a console application does not mean automatically that it runs on the server. – pholpar Jan 18 '18 at 11:32
  • Yes, this is exactly what I thought but unfortunately, he didn't mention any more details about his requirements, Thank you for your valuable feedback :) – Mohamed El-Qassas MVP Jan 18 '18 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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