SearchContext.GetContext Method (SPSite)

Gets the search context instance for the specified SPSite object.

Namespace:  Microsoft.Office.Server.Search.Administration
Assembly:  Microsoft.Office.Server.Search (in Microsoft.Office.Server.Search.dll)

public static SearchContext GetContext(
	SPSite site


Type: Microsoft.SharePoint.SPSite

If you specify an SPSite object in the GetContext method to retrieve the search context, we recommend that your code instantiates the SPSite object within a using statement to ensure the object is released once it's no longer needed. See code in the Example section.

For more information about the SearchContext class and the Enterprise Search Administration object model, see Getting Started with the Enterprise Search Administration Object Model and How to: Return the Search Context for the Search Service Provider.


SearchContext context;
using (SPSite site = new SPSite("http://yourSiteName"))
     context = SearchContext.GetContext(site);


Community Additions