This article will show you how you can manage the different search settings using CSOM. It will configure the search settings in the same way that you can do from the “Search settings” option in the Site settings:

clip_image002

Note that, obviously, the Search Settings that will apply, are the ones defined at Web level. The Site collection level only applies if in the Web level you are selecting: “Use the same results page settings as my parent.”, and actually, what it does is to copy the values to the Web site level.

This is how the Search settings page looks:

clip_image004

The “Configure Search Navigation” option is only available from Web Search settings, and that means you cannot inherit search navigation nodes (as far as I’ve seen). In order to add new Navigation links, the best option is to use the Pnp Core project, and use a handy extension for the Web object, so you can do something like:


Note that if the page is not in the same Site collection, you have to set the “isExternal” param to true, or you will get an exception when saving changes.

For the other settings, there are no specific CSOM code to configure them. However, SharePoint saves that information in some PropertyBags, so we just need to Update that PropertyBags values with the right information. Here are the PropertyBags that SharePoint uses:

At Site collection search settings level:

image

Remember that these settings doesn’t apply to the RootWeb. They are only used to copy these values when a subsite is created and it inherits the settings from their parent.

At Web search settings level:

image

Considering this, all you have to do to configure Search Settings from CSOM, is to set the property bag value, and again, we can use another Web extension from Pnp Core project:


Finally, keep in mind that all these settings apply mainly to the Default search text box control, as you can override some of them from the Search box web part:

clip_image010