5

I am trying to find if that is possible to change site's search navigation(a.k.a search dropdown links) through CSOM?

Seems Search's export configuration does not contain info about search navigation(Site Settings->Search->Search Settings), and i am struggling to find any article that describes whether this is doable through CSOM.

Any help would be highly appreciated.

Thanks

2

The node id for site navigation is 1040, so: i use this for clear all site navigation nodes from a site:

NavigationNodeCollection lNodes = ctx.Web.Navigation.GetNodeById(1040).Children;
ctx.Load(lNodes);
ctx.ExecuteQuery();

lNodes.ToList().ForEach(node => node.DeleteObject());
ctx.ExecuteQuery();

this is to delete some existing node navigation by its title:

NavigationNodeCollection lNodes = ctx.Web.Navigation.GetNodeById(1040).Children;
ctx.Load(lNodes);
ctx.ExecuteQuery();

NavigationNode lNode = lNodes.ToList().Find(node => node.Title.Equals(this.Title));
lNode.DeleteObject();
ctx.ExecuteQuery();

this is to add some new node navigation:

NavigationNodeCollection lNodes = ctx.Web.Navigation.GetNodeById(1040).Children;
ctx.Load(lNodes);
ctx.ExecuteQuery();

NavigationNodeCreationInformation nnci = new NavigationNodeCreationInformation();
nnci.Url = "http://sharepoint.stackexchange.com/";
nnci.Title = "SharePoint";
nnci.AsLastNode = true;

NavigationNode lNode = lNodes.Add(nnci);
ctx.ExecuteQuery();
  • Please provide context for links and quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. – jcp Dec 21 '15 at 15:26
  • 1
    Ok, I totally agree with your comments and edit the post with reference to my code. Thanks and sorry. – Ignacio D'Alto May 4 '16 at 14:51
0

I think these settings are all set through the Property bag. Try setting some stuff in the UI then inspect the property bag for that web.

Here's an old article I wrote years ago about how to do this: https://www.nothingbutsharepoint.com/sites/devwiki/articles/Pages/Making-use-of-the-Property-Bag-in-the-ECMAScript-Client-Object-Model.aspx

(in short, in case the link dies one day, use Web.get_allProperties() then cycle through the result, or use get_item('key_name') to get a value out).

  • 1
    Thanks for reply. Unfortunately could not find anything in the property bag after setting few navigation links for search. will post answer here if i find anything. – David Sep 29 '14 at 9:34
0

I know this post is a few months old, but I ran into this myself recently and documented the solution here: http://sharepointtaproom.com/2015/02/17/missing-searchnav-property-in-sharepoint-client-object-model/

In server-side code, you'd use the SPNavigation.SearchNav property to customize the search menu. However, the client-side object model doesn't include that property. Instead, you have to access a special "search root" node as documented in the blog post I linked to and add/remove child nodes to/from that root node to customize the menu.

I used that approach recently to write a scheduled job in Windows Azure that copies search navigation settings from a parent site to all the child sites in my collection (since SharePoint 2013 doesn't let child sites inherit search navigation settings, unfortunately). Since the job was hosted in Azure, I had to use the client object model to accomplish this.

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.