ARTICLE

Programmatically how to retrieve the Content Sources from Search Service application in SharePoint 2010

Posted by Vijai Anand Articles | SharePoint 2010 January 26, 2011
In this article we will be seeing how to retrieve all the content sources from search service application in SharePoint 2010.
Reader Level:

In this article we will be seeing how to retrieve all the content sources from search service application in SharePoint 2010.

If you go to Central Administration => Application Management => Manage service applications => Search Service Application => Crawling => Content Sources you could see all the content sources.

image1.gif

C# code:

  • Open Visual Studio 2010.
  • Go to File => New => Project.
  • Select Console Application from the installed templates.
  • Enter the Name and click Ok.
  • Add the following references.

    o Microsoft.SharePoint.dll
    o Microsoft.Office.Server.dll
    o Microsoft.Office.Server.Search.dll
     
  • Add the following namespaces.

    o using Microsoft.Office.Server.Search.Administration;
    o using Microsoft.Office.Server;
    o using Microsoft.SharePoint;
     
  • Replace the code with the following.

    //  search service application name   
                string ssaName ="Search Service Application";
                SearchContext context =SearchContext.GetContext(ssaName);
    Content ssaContent = new Content(context);
                ContentSourceCollection ssaContentSources = ssaContent.ContentSources;
                foreach (ContentSource cs in ssaContentSources)
                {
                    Console.WriteLine("Content Source Name: " + cs.Name + "  ID: " + cs.Id);
                    Console.ReadLine();
                }

     
  • Build the solution.
  • Hit F5. 

Login to add your contents and source code to this article
comments
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Nevron Diagram
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
HTML 5 + JQUERY CONTROLS