Share via


[方法] 共有サービス プロバイダのコンテンツ ソースを取得する

エンタープライズ検索 管理オブジェクト モデルの Content オブジェクトは、共有サービス プロバイダ (SSP) の検索サービス用に構成されたコンテンツ ソースへのアクセスを提供します。

次に示す手順は、コンソール アプリケーションからコンテンツ ソースの名前と ID の完全な一覧を書き出す方法です。

コンソール アプリケーションからコンテンツ ソースの名前と ID の一覧を表示するには

  1. アプリケーションで、以下の DLL への参照を設定します。

    • Microsoft.SharePoint.dll

    • Microsoft.Office.Server.dll

    • Microsoft.Office.Server.Search.dll

  2. コンソール アプリケーションのクラス ファイルで、他の名前空間ディレクティブを含むコードの先頭近くに次の using ステートメントを追加します。

    using Microsoft.SharePoint;
    using Microsoft.Office.Server.Search.Administration;
    
  3. SSP の検索コンテキストの Content オブジェクトを取得するには、以下のコードを追加します。検索コンテキストの取得方法の詳細については、「[方法] 検索サービス プロバイダに検索コンテキストを返す」を参照してください。

    /*
    Replace <SiteName> with the name of a site using the SSP
    */
    string strURL = "http://<SiteName>";
    SearchContext context;
    using (SPSite site = new SPSite(strURL))
    {
        Context = SearchContext.GetContext(site);
    }
    Content sspContent = new Content(context);
    
  4. 以下のコードを使用して、コンテンツ リソースのコレクションを取得します。

    ContentSourceCollection sspContentSources = sspContent.ContentSources;
    
  5. コンテンツ ソースをループして各コンテンツ ソースの名前と ID を表示するには、次のコードを追加します。

    foreach (ContentSource cs in sspContentSources)
    {
       Console.WriteLine("NAME: " + cs.Name + "  ID: " + cs.Id);
    }  
    

以下に、コンソール アプリケーション クラスのサンプルの完全なコードを示します。

前提条件

  • 共有サービス プロバイダが既に作成されていることを確認します。

プロジェクト参照

このサンプルを実行する前に、コンソール アプリケーション コード プロジェクトに以下のプロジェクト参照を追加します。

  • Microsoft.SharePoint

  • Microsoft.Office.Server

  • Microsoft.Office.Server.Search

using System;
using System.Collections;
using System.Text;
using Microsoft.Office.Server.Search.Administration;
using Microsoft.SharePoint;

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

            foreach (ContentSource cs in sspContentSources)
            {
                Console.WriteLine("NAME: " + cs.Name + "  ID: " + cs.Id);
            }
        }
    }
}

See Also

タスク

[方法] 検索サービス プロバイダに検索コンテキストを返す

[方法] コンテンツ ソースを追加する

[方法] コンテンツ ソースを削除する

[方法] コンテンツ ソースのクロールをプログラム的に管理する

[方法] コンテンツ ソースのクロール スケジュールをプログラムで構成する

概念

エンタープライズ検索管理オブジェクト モデルを使うにあたって

コンテンツ ソースの概要