sumit kumar

sumit kumar

  • NA
  • 158
  • 2.4k

Query Site Collection Level Result Source in C#

Nov 30 2015 3:00 AM
I have created a result source at site collection level from SharePoint UI but when trying to get result source in code it's not coming at all only default result source which SharePoint provides those only coming. Is there any other way to refer custom result source in C# in SharePoint 2013. Below is the code which I am trying:
 
string resultSourceId  = string.Empty;
SearchQueryAndSiteSettingsServiceProxy settingsProxy = SPFarm.Local.ServiceProxies.GetValue<SearchQueryAndSiteSettingsServiceProxy>();
SearchServiceApplicationProxy searchProxy = settingsProxy.ApplicationProxies.GetValue<SearchServiceApplicationProxy>("Search Service Application");
SearchObjectOwner siteCollectionOwner = new SearchObjectOwner(SearchObjectLevel.SPSite, web);
SourceRecord siteCollectionResultSource = searchProxy.GetResultSourceByName("CustomResultSourceName", siteCollectionOwner);
string resultSourceId = siteCollectionResultSource.Id.ToString();
 

Answers (1)