Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The Content object in the Enterprise Search Administration object model provides access to the content sources configured for the search service of a Shared Services Provider (SSP).
The following procedure shows how to write out the full list of content source names and IDs from a console application.
To display the list of content source names and IDs from a console application
In your application, set references to the following DLLs:
Microsoft.SharePoint.dll
Microsoft.Office.Server.dll
Microsoft.Office.Server.Search.dll
In your console application's class file, add the following using statements near the top of the code with the other namespace directives.
using Microsoft.SharePoint; using Microsoft.Office.Server.Search.Administration;To retrieve the Content object for the SSP's search context, add the following code. For more information about ways to retrieve the search context, see How to: Return the Search Context for the Search Service Provider.
/* Replace <SiteName> with the name of a site using the SSP */ string strURL = "http://<SiteName>"; SearchContext context; using (SPSite site = new SPSite(strURL)) { Context = SearchContext.GetContext(site); } Content sspContent = new Content(context);Retrieve the collection of content sources by using the following code.
ContentSourceCollection sspContentSources = sspContent.ContentSources;To loop through the content sources and display the name and ID for each content source, add the following code.
foreach (ContentSource cs in sspContentSources) { Console.WriteLine("NAME: " + cs.Name + " ID: " + cs.Id); }
Example
Following is the complete code for the console application class sample.
Prerequisites
- Ensure a Shared Services Provider is already created.
Project References
Add the following Project References in your console application code project before running this sample:
Microsoft.SharePoint
Microsoft.Office.Server
Microsoft.Office.Server.Search
using System;
using System.Collections;
using System.Text;
using Microsoft.Office.Server.Search.Administration;
using Microsoft.SharePoint;
namespace ContentSourcesSample
{
class Program
{
static void Main(string[] args)
{
/*
Replace <SiteName> with the name of a site using the SSP
*/
string strURL = "http://<SiteName>";
SearchContext context;
using (SPSite site = new SPSite(strURL))
{
context = SearchContext.GetContext(site);
}
Content sspContent = new Content(context);
ContentSourceCollection sspContentSources = sspContent.ContentSources;
foreach (ContentSource cs in sspContentSources)
{
Console.WriteLine("NAME: " + cs.Name + " ID: " + cs.Id);
}
}
}
}
See Also
Tasks
How to: Return the Search Context for the Search Service Provider
How to: Add a Content Source
How to: Delete a Content Source
How to: Programmatically Manage the Crawl of a Content Source
How to: Programmatically Configure a Crawl Schedule for a Content Source
Concepts
Getting Started with the Enterprise Search Administration Object Model
Content Sources Overview