Share via


[方法] ルールに基づく対象ユーザーを作成する

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

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

注意

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

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

  • Microsoft.Office.Server

  • 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"))
                {
                    ServerContext context = ServerContext.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();
            }

        }
    }


}

See Also

その他のリソース

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