Reader Level:
Articles

How to delete the Content Sources from Search Service application in SharePoint 2010

By Vijai Anand on Jan 27, 2011
In this article we will be seeing how to delete all the content sources from search service application in SharePoint 2010.
  • 0
  • 0
  • 8656

In this article we will be seeing how to delete 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;
                   ContentSource cs = ssaContentSources["Local SharePoint Sites"];
                cs.Delete(); 

     
  • Build the solution.
  • Hit F5.

Vijai Anand

Vijai Anand has been working in IT industry for over 5 years. He holds Bachelor's degree in Electronics and Communication Engineering. Vijai write articles and blogs related to SharePoint 2013, SharePoint 2010, Silv... Read more

COMMENT USING

Trending up