ルールに基づく対象ユーザーを作成する

最終更新日: 2010年1月27日

適用対象: SharePoint Server 2010

Microsoft SharePoint Server 2010 は、対象ユーザー ルール、SharePoint グループ、Microsoft Exchange 配布リスト (DL) メンバ-シップに基づくコンテンツの対象設定をサポートします。また、SharePoint Server 2010 は、リスト レベルだけではなく、リスト アイテム レベルでコンテンツの対象を設定する機能を提供します。

このコード例は、コンテンツの対象にできるルールに基づいた対象ユーザーを作成する方法を示しています。

注意

ここでは、対象ユーザーを作成するだけで、コンパイルは行われず、ルールは追加されていません。ユーザー インターフェイスまたはオブジェクト モデルを使用してルールを追加し、ユーザー インターフェイスを使用して対象ユーザーをコンパイルできます。対象ユーザーのコンパイルは、オブジェクト モデルではサポートされません。

コード例を実行する前に、servername とその他の文字列を実際の値に置き換えます。また、Microsoft Visual Studio プロジェクトに次の参照を追加します。

  • Microsoft.Office.Server

  • Microsoft.Office.Server.UserProfiles

  • Microsoft.SharePoint

  • System.Web

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.Administration;
using Microsoft.Office.Server.Audience;
using Microsoft.SharePoint;
using Microsoft.Office.Server;
using System.Web;

namespace AudienceConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                using (SPSite site = new SPSite("https://servername"))
                {
                    SPServiceContext context = SPServiceContext.GetContext(site);
                    AudienceManager audManager = new AudienceManager(context);

                    AudienceCollection ac = audManager.Audiences;
                    Audience a = null;
                    string sAudName = "Customer Connection";
                    string sDescription = "Members of the Customer Connection v-team";

                    try
                    {
                        a = ac.Create(sAudName, sDescription);
                    }
                    catch (AudienceDuplicateNameException e)
                    {
                        //Your exception handling code here
                    }
                    catch (AudienceException e1)
                    {
                        //Your exception handling code here
                    }
                }

            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.ToString());
                Console.Read();
            }

        }
    }


}

関連項目

その他の技術情報

対象ユーザーを使用してコンテンツを設定する