如何:创建基于规则的访问群体

上次修改时间: 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();
            }

        }
    }


}

请参阅

其他资源

使用访问群体设定内容