Audience 类

表示 SharePoint 网站上的读者。

继承层次结构

System.Object
  Microsoft.Office.Server.Audience.Audience

命名空间:  Microsoft.Office.Server.Audience
程序集:  Microsoft.Office.Server.UserProfiles(位于 Microsoft.Office.Server.UserProfiles.dll 中)

语法

声明
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
Public Class Audience
用法
Dim instance As Audience
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
public class Audience

备注

观众是决定通过在 Microsoft Exchange 通讯组列表 (DL) 或 SharePoint 组,其成员资格或通过门户管理员配置规则的用户的组。例如,您可以设置新员工、 管理人员、 销售人员或人从指定城市为观众。(如果此信息保留在活动目录中),可以基于信息在用户配置文件,或组织的汇报结构上在 Active Directory 目录服务安全组或 Exchange 通讯组列表成员资格的访问群体规则。

访问群体允许组织根据他们的作业或任务时,对用户的目标内容,规定其 SharePoint 组或通讯组列表中的成员资格、 组织报告结构,或其用户配置文件中的公共属性。

您可以将基于的受众、 SharePoint 组和 DL 成员身份。此外,可以将目标列表项级别,而不是只在列表级别。

示例

此代码示例演示如何创建基于规则的访问群体可以向其目标内容。

备注

访问群体时才创建 ;它不被编译,并尚未添加规则。可以通过用户界面或对象模型,添加规则,然后通过使用用户界面中搜集访问群体。在对象模型中不支持搜集访问群体。

在运行此代码示例前用实际值替换servername和其他字符串。在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)
                    {
                        //Add your exception handling code here.
                    }
                    catch (AudienceException e1)
                    {
                        //Add your exception handling code here.
                    }
                }

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

        }
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SharePoint.Administration
Imports Microsoft.Office.Server.Audience
Imports Microsoft.SharePoint
Imports Microsoft.Office.Server
Imports System.Web

Namespace AudienceConsoleApp
    Module Program
        Sub Main(ByVal args() As String)
            Try
                Using site As New SPSite("https://servername")
                    Dim context As ServerContext = ServerContext.GetContext(site)
                    Dim audManager As New AudienceManager(context)

                    Dim ac As AudienceCollection = audManager.Audiences
                    Dim a As Audience = Nothing
                    Dim sAudName As String = "Customer Connection"
                    Dim sDescription As String = "Members of the Customer Connection v-team"

                    Try
                        a = ac.Create(sAudName, sDescription)
                    Catch e As AudienceDuplicateNameException
                        'Add your exception handling code here.
                    Catch e1 As AudienceException
                        'Add your exception handling code here.
                    End Try
                End Using

            Catch exception As Exception
                Console.WriteLine(exception.ToString())
                Console.Read()
            End Try

        End Sub
    End Module
End Namespace

线程安全性

该类型的任何公共 静态 (已共享 在 Visual Basic 中) 成员都是线程安全的。不保证任何实例成员都是线程安全的。

另请参阅

引用

Audience 成员

Microsoft.Office.Server.Audience 命名空间