Export SharePoint Site Search Configuration using Client Object Model C#

To export 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; 
string searchConfiguration = String.Empty;

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

SearchConfigurationPortability searchConfigurationPortability = new SearchConfigurationPortability(ctx);
SearchObjectOwner searchObjectOwner = new SearchObjectOwner(ctx, SearchObjectLevel.SPSite);
ClientResult<string> crSearchConfig = searchConfigurationPortability.ExportSearchConfiguration(searchObjectOwner);
ctx.ExecuteQuery();

if (crSearchConfig != null && !String.IsNullOrWhiteSpace(crSearchConfig.Value))
{
    //Get the search configuration as string
    searchConfiguration = crSearchConfig.Value;
}

Check out my other blog at, https://realmpksharepoint.wordpress.com/2014/03/04/import-sharepoint-site-search-configuration-using-client-object-model-c/, to know how to import an exported search configuration to a site

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