Delete Method

ContentSource.Delete Method

Deletes the content source.

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

public void Delete()

The following code example deletes a content source from a Shared Service Provider's collection of content sources. For a complete, step-by-step walkthrough of this sample code, see How to: Delete a Content Source.


Ensure a Shared Service 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.Generic;
using System.Text;
using Microsoft.Office.Server.Search.Administration;
using Microsoft.SharePoint;

namespace DeleteContentSourceSample
    class Program
        static void Main(string[] args)
                //Replace <SiteName> with the name of a site using the Shared Service Provider.
                string strURL = "<SiteURL>";
                Content sspContent = new Content(SearchContext.GetContext(new SPSite(strURL)));
                ContentSourceCollection sspContentSources = sspContent.ContentSources;
                //Replace <ContentSourceName> with the ID for the content source to delete.
                string strCSName = "<ContentSourceName>";
                ContentSource contentSource = sspContentSources[strCSName];
                Console.WriteLine(strCSName + " deleted.");
            catch (Exception e)

Community Additions

© 2016 Microsoft