I am working on a solution in SharePoint Online where I want to accomplish the following using CSOM:

  1. Update rootweb search navigation (also known as search verticals) to display "Search everywhere" instead of "Search this site" in the search box
  2. Set all subsites to inherit search navigation from parent

Issue 1

I found an article explaining how the SPNavigation.SearchNav was introduced in SharePoint 2013 and gives you access to the list of navigation nodes with server-side code. However, since this is not available in the client-side object model, we need to use a slightly different approach.

Web rootWeb = clientContext.Site.RootWeb;
NavigationNode searchNavRoot = rootWeb.Navigation.GetNodeById(1040);
clientContext.Load(searchNavRoot, root => root.Children);

NavigationNodeCollection searchNavColl = searchNavRoot.Children;

This retrieves the navigation nodes for the vertical search well-enough, but ONLY if you have edited it before through the UI - else it returns 0 elements.

So my best bet right now is to simply add them by code, to have the default search vertical set to "Search everywhere" as shown here:

NavigationNodeCollection searchNavColl = searchNavRoot.Children;
if (searchNavColl.Count == 0) // if navigation is not set, add nodes 
    NavigationNode everywhere = CreateNavigationNode(searchNavColl, true, true, "Everywhere", "/search/Sider/results.aspx", null);
    NavigationNode people = CreateNavigationNode(searchNavColl, true, true, "People", "/search/Sider/peopleresults.aspx", null);
    NavigationNode conversation = CreateNavigationNode(searchNavColl, true, true, "Conversations", "/search/Sider/conversationresults.aspx", null);
    NavigationNode thisSite = CreateNavigationNode(searchNavColl, true, true, "This site", "/_layouts/15/osssearchresults.aspx?u={contexturl}", null);

If you know another way of achieving this, I am all ears.

Issue 2

Looking at some examples I was able to create this little code-snippet which actually works and sets a property on a subsite web to inherit parent search navigation.

Web web = clientContext.Site.OpenWeb("/sites/ARN/test");
var allProperties = web.AllProperties;

web.AllProperties["SRCH_VERT_SET_WEB"] = "{\"Inherit\":true}";
clientContext.Load(web, w => w.AllProperties);

However, even though the property is updated and search settings are now set to inherit parent navigation - it's not working.

I need to navigate to "Site settings > Search settings" and click OK for it actually work. So it seems like I am missing an Update of some kind...

Any help would be much appreciated.


This is directed at your Issue 2 - I was struggling with almost an identical problem in that I was trying to get a new site to create using global Managed Navigation inherited from the parent site. The code I was using would change the radio button, but the changed didn't seem to apply until I went in manually and hit OK. The second example on this site by Albert-Jan Schot solved the problem for me.

TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);

WebNavigationSettings navigationSettings = new WebNavigationSettings(clientContext, clientContext.Web);
navigationSettings.CurrentNavigation.Source = StandardNavigationSource.PortalProvider;

The "PortalProvider" option can be changed to represent the desired option (structured, managed, inherit from parent).

Your desired outcome seems to be slightly different to mine, but I hope this can assist.

  • It does sound like an identical issue, but I still don't know what to do to force the change. I've tried to load in the NavigationNode searchNavRoot property from issue 1 and update that as well. No luck. – Anders Nielsen Jul 12 '17 at 10:17
  • @AndersNielsen: Were you ever able to fix the problem you were having in issue #2? – Jim Barntish Aug 3 '17 at 16:17
  • @JimBarntish unfortunately no. – Anders Nielsen Sep 5 '17 at 6:37

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.