5

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

  • Set all subsites to inherit search navigation from parent. To achieve this I have this little code-snippet which actually works and sets a property on a subsite web to inherit parent search navigation.

            using (ClientContext context = new ClientContext("ParentSiteURL"))
            {
            context.Credentials = new SharePointOnlineCredentials(struser, password);
            Web web = context.Site.OpenWeb("SubsiteName");
            var allProperties = web.AllProperties;
            context.Load(allProperties);
            web.AllProperties["SRCH_VERT_SET_WEB"] = "{\"Inherit\":true}";
            web.Update();                
            context.ExecuteQuery();
            }
    

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.

2
  • Do you have managed termset based navigation on rootsite?
    – DvG
    Jul 2, 2018 at 7:46
  • Nope. I don't have any managed termset.
    – Ravi
    Jul 2, 2018 at 7:50

2 Answers 2

0

I think you have to load it before execute

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

as said in this post

1
  • Already tried. Not Working :(
    – Ravi
    Jul 2, 2018 at 8:47
0

Using the property SRCH_VERT_SET_WEB is probably not the right way to do it, since there is no documentation on the subject.

Try a more straight-forward approach like changing SPWeb.Navigation properties.

Check the propertiy values for UseShared and the list of navigation nodes in SearchNav before and after you modify search inheritance via site settings. You should be able to figure out what changed in the object model and then re-apply it in your code.

2
  • I set UseShared property to true after loading all the navigation nodes. And still it does not work :(
    – Ravi
    Jul 2, 2018 at 9:28
  • Finally I was able to achieve it using HttpPost method. Answered it on the originial question as I am unable to do answer it here. Thanks
    – Ravi
    Aug 1, 2018 at 10:40

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