Import SharePoint Site Search Configuration using Client Object Model C#

In my previous post,, I had demonstrated how to export the Search Configuration of a SharePoint site.  Here, I will show how to import an exported search configuration.

To import the Search Configuration, we have to use the following namespace

using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Search.Administration; 
using Microsoft.SharePoint.Client.Search.Portability; 

In the following code, the string variable, searchConfiguration, holds the search configuration

ClientContext ctx = new ClientContext(weburl);
ctx.Credentials = new SharePointOnlineCredentials(userName, passWord);
SearchConfigurationPortability searchConfigurationPortability =

new SearchConfigurationPortability(ctx);
SearchObjectOwner searchObjectOwner = new SearchObjectOwner(ctx, SearchObjectLevel.SPWeb);

searchConfigurationPortability.ImportSearchConfiguration(searchObjectOwner, searchConfiguration);