Partager via


ContentSourceCollection.Create, méthode (Microsoft.Office.Server.Search.Administration)

Creates a new content source in the collection.

Espace de noms : Microsoft.Office.Server.Search.Administration
Assembly : Microsoft.Office.Server.Search (dans microsoft.office.server.search.dll)

Syntaxe

'Déclaration
Public Function Create ( _
    type As Type, _
    name As String _
) As ContentSource
'Utilisation
Dim instance As ContentSourceCollection
Dim type As Type
Dim name As String
Dim returnValue As ContentSource

returnValue = instance.Create(type, name)
public ContentSource Create (
    Type type,
    string name
)

Paramètres

  • type
    The object type of the content source.
  • name
    A string containing the content source name.

Valeur de retour

A ContentSource object.

Remarques

For more information about content sources and the new Recherche de contenu d'entreprise Administration object model, see Vue d'ensemble des sources de contenu, and Getting Started with the Search Administration Object Model.

Exemple

The following code example creates a new custom content source. For a complete, step-by-step walkthrough of the sample code for the Create method of the ContentSourceCollection class, see Procédure : ajouter une source de contenu.

Prerequisites

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 AddContentSourceSample
{
    class Program
    {
        static void Main(string[] args)
        {
            /*
            Replace <SiteName> with the name of a site
            using the Shared Service 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>");

        }
    }
}

Voir aussi

Référence

ContentSourceCollection, classe
Membres ContentSourceCollection
Microsoft.Office.Server.Search.Administration, espace de noms