Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Create method (Type, String)
Collapse the table of content
Expand the table of content

ContentSourceCollection.Create method (Type, String)

Creates a content source in the collection.

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

public ContentSource Create(
	Type type,
	string name
)

Parameters

type
Type: System.Type

The object type of the content source.

name
Type: System.String

A string containing the content source name.

For more information about content sources and the new SharePoint Enterprise Search Administration object model, see Content Sources Overview and Getting Started with the Search Administration Object Model.

The following code example creates a custom content source. For a complete, step-by-step walkthrough of the example code for the Create() method of the ContentSourceCollection class, see How to: Add a Content Source.

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

namespace AddContentSourceSample
{
    class Program
    {
        static void Main(string[] args)
        {
            /*
            Replace <SiteName> with the name of a site
            using the Shared Services Provider.
            */
            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;
            // Replace <csName> with the content source name.
            CustomContentSource customCS = (CustomContentSource)sspContentSources.Create(typeof(CustomContentSource), "<csName>");

        }
    }
}
Show:
© 2015 Microsoft