Get SearchContext programmatically in SharePoint 2007

By Jatin Prajapati

How to get SearchContext programmatically using SharePoint Object Model.

Following code example show you how to get the SearchContext using SharePoint Object Model.

using System;
using System.Collections;
using System.Text;
using Microsoft.Office.Server.Search.Administration;
using Microsoft.SharePoint;

namespace Jatin
{
public class GetSearchContext
{
static void Main(string[] args)
{
string siteURL = "http://localhost:20918";
SearchContext searchContext;
using(SPSite site = new SPSite(siteURL))
{
searchContext = SearchContext.GetContext(site);
}
Content serviceProviderContent = new Content(searchContext);
ContentSourceCollection sspContentSources = serviceProviderContent.ContentSources;
foreach(ContentSource contentSource in sspContentSources)
{
Console.WriteLine("Content Source: " + contentSource.Name);
}
}
}
}

Get SearchContext programmatically in SharePoint 2007  (674 Views)