다음을 통해 공유


Audience Class

Represents an audience on a SharePoint Server 2010 site.

Inheritance Hierarchy

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

Namespace:  Microsoft.Office.Server.Audience
Assembly:  Microsoft.Office.Server.UserProfiles (in Microsoft.Office.Server.UserProfiles.dll)

Syntax

'Declaration
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public Class Audience
'Usage
Dim instance As Audience
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public class Audience

Remarks

Audiences are groups of users determined by their memberships in Microsoft Exchange distribution lists (DL) or SharePoint groups, or by rules configured by a portal administrator. For example, you can set up new employees, executives, salespeople, or people from a specified city as audiences. In SharePoint Server 2010, you can base the audience rules on information in the user profile, on membership in an Active Directory directory service security group or an Exchange distribution list, or on the organization's reporting structure (if this information is kept in Active Directory).

Audiences allow organizations to target content to users based on their job or task, as defined by their membership in a SharePoint group or distribution list, by the organizational reporting structure, or by the public properties in their user profiles.

SharePoint Server 2010 supports targeting based on audience, SharePoint groups, and DL memberships. In addition, SharePoint Server 2010 provides the ability to target to the list-item level, rather than just to the list level.

Examples

This code example shows how to create a rules-based audience to which you can target content.

Note

The audience is only created here; it is not compiled, and rules have not been added. You can add rules by using the user interface or the object model, and then compile the audience by using the user interface. Compiling audiences is not supported in the object model.

Replace servername and other strings with actual values before running the code example. Also add the following references in your Visual Studio project:

  • 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

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

Audience Members

Microsoft.Office.Server.Audience Namespace