Import SharePoint Site Search Configuration using Client Object Model C#

In my previous post, https://realmpksharepoint.wordpress.com/2014/03/03/export-sharepoint-site-search-configuration-using-client-object-model-c/, 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);
ctx.ExecuteQuery(); 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s