Monday, February 16, 2009

Reading all available content sources

Scenario:
While writing a small utility I was suppose to read all the avilable content sources.

Solution:
Small console application

Code:

using System;
using System.Collections;
using System.Text;
using Microsoft.Office.Server.Search.Administration;
using Microsoft.SharePoint;
class Program
{
static void Main(string[] args)
{
string siteURL = "http://localhost";
SearchContext context;
using(SPSite spSite = new SPSite(siteURL))
{
context = SearchContext.GetContext(spSite);
}
Content sspContent = new Content(context);
ContentSourceCollection sspContentSources = sspContent.ContentSources;
foreach (ContentSource contentSource in sspContentSources)
{
Console.WriteLine("Content Source: " + contentSource.Name )
}
}
}

0 comments: