AudienceManager AudienceManager AudienceManager Class

Definition

Represents the entry point for the audience classes.

public ref class AudienceManager : Microsoft::SharePoint::WebPartPages::IRuntimeFilter2
public class AudienceManager : Microsoft.SharePoint.WebPartPages.IRuntimeFilter2
Public Class AudienceManager
Implements IRuntimeFilter2
Inheritance
AudienceManagerAudienceManagerAudienceManager
Implements

Examples

<p>This code example shows how to create a rules-based audience to which you can target content. </p>
<p>
  <strong>Note</strong>: 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. You can also compile audiences by using the <xref data-throw-if-not-resolved="true" uid="Microsoft.Office.Server.Audience.AudienceJob"></xref> class.</p>
<p>Replace servername and other strings with actual values before running the code example. Also add the following references in your Microsoft Visual Studio project:</p>
<ul><li>Microsoft.Office.Server</li><li>Microsoft.SharePoint</li><li>System.Web</li></ul>
<pre><code>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("http://<span class="placeholder">servername</span>")) { 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();
        }

    }
}

}

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("http://servername")
                    Dim context As SPServiceContext = SPServiceContext.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
                        'Your exception handling code here
                    Catch e1 As AudienceException
                        '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

Remarks

The AudienceManager class is the entry point for the audience feature in Microsoft SharePoint Server 2010. It provides an implementation of IRuntimeFilter, which allows Web Parts and other content to be targeted to a specific audience. The AudienceManager class supports run-time functionality such as the retrieval of audience lists to which the user belongs. After you create an instance of the AudienceManager class, you can retrieve individual audience types, lists of audiences, and lists of users who are associated with an audience.

There are several default authentication rules and scopes implemented for the AudienceManager object:

  • Members of the Administrator site group for SharePoint Server can view and modify the audiences associated with a portal site.
  • Members of the Administrator site group can also view audience information for other portal sites with which they share services. Shared services are portal services that are shared across server farms. The services are centrally managed from a single server for two or more server farms.
  • Members of the Administrator site group of the parent portal site can list and view audience information for child portal sites. This information is read-only.
  • A member of the Reader or Contributor site group can access only a list of audiences to which he or she belongs. This information is returned by the overloaded GetUserAudienceIDs method.

Constructors

AudienceManager() AudienceManager() AudienceManager()

Initializes a new instance of the AudienceManager class.

AudienceManager(ServerContext) AudienceManager(ServerContext) AudienceManager(ServerContext)

Initializes a new instance of the AudienceManager class that connects to the site in the specified SPServiceContext object.

AudienceManager(SPServiceContext) AudienceManager(SPServiceContext) AudienceManager(SPServiceContext)

AudienceManager constructure. No input, will retrieve current URL request as site URL

Fields

GUID_AllPortalUser GUID_AllPortalUser GUID_AllPortalUser

Gets a new GUID for a user in the Everyone Global Audience.

Properties

AudienceLeftContentList AudienceLeftContentList AudienceLeftContentList

Gets an ArrayList object of AudienceLeftContent objects.

AudienceOperatorList AudienceOperatorList AudienceOperatorList

Gets an ArrayList object that contains references to AudienceOperator objects.

Audiences Audiences Audiences

Gets the collection of Audience objects for the current site.

CurrentServerContext CurrentServerContext CurrentServerContext

Gets the reference to the SPServiceContext object with which this object was initialized.

SiteGuid SiteGuid SiteGuid

Gets the globally unique identifier (GUID) for the current site.

SiteURL SiteURL SiteURL

Gets the URL for the current site.

Methods

CheckRuntimeRender(String) CheckRuntimeRender(String) CheckRuntimeRender(String)

Checks whether the audience membership of the current user is contained in the audience list of any Web Parts in this Web site based on Microsoft Windows SharePoint Services.

GetAudience(Guid) GetAudience(Guid) GetAudience(Guid)

Gets an instance of the Audience object that represents the audience with the specified globally unique identifier (GUID).

GetAudience(String) GetAudience(String) GetAudience(String)

Gets an instance of the Audience object that represents the audience with the specified name.

GetAudienceIDs(ArrayList) GetAudienceIDs(ArrayList) GetAudienceIDs(ArrayList)

Gets a list of AudienceNameID objects that correspond to the specified list of audience names.

GetAudienceIDsAsText(String[], String[], String[]) GetAudienceIDsAsText(String[], String[], String[]) GetAudienceIDsAsText(String[], String[], String[])

Creates a delimited text representation of the specified Audience objects’ identifiers.

GetAudienceIDsFromText(String, String[], String[], String[]) GetAudienceIDsFromText(String, String[], String[], String[]) GetAudienceIDsFromText(String, String[], String[], String[])

Counts the number of Audience object identifiers in a delimited string and loads the parsed identifiers in string Arrays.

GetAudienceNames(ArrayList) GetAudienceNames(ArrayList) GetAudienceNames(ArrayList)

Gets a list of AudienceNameID objects that correspond to the specified list of audience globally unique identifiers (GUIDs).

GetAudienceOperator(String) GetAudienceOperator(String) GetAudienceOperator(String)

Gets a list of AudienceOperator objects that correspond to the specified operand.

GetToolPaneControl() GetToolPaneControl() GetToolPaneControl()

Requests an IToolPaneControl interface.

GetUserAudienceIDs(Boolean) GetUserAudienceIDs(Boolean) GetUserAudienceIDs(Boolean)

Gets a list of globally unique identifiers (GUIDs) for the audiences to which the current user belongs.

GetUserAudienceIDs(String, Boolean, SPWeb) GetUserAudienceIDs(String, Boolean, SPWeb) GetUserAudienceIDs(String, Boolean, SPWeb)

Gets a list of audience globally unique identifiers (GUIDs) for the specified user name.

InitializeStrings(CultureInfo) InitializeStrings(CultureInfo) InitializeStrings(CultureInfo)

Initializes an array of strings that are used by the audience Web Part.

IsCurrentUserInAudienceOf(String, Boolean) IsCurrentUserInAudienceOf(String, Boolean) IsCurrentUserInAudienceOf(String, Boolean)

This method will check whether current user's Audience membership belong to any audience as defined within audienceTextRepresentation. If does, return true, else return false. If there is any exception occured, this function will return false and log the exception, raise ShipAssert()

IsCurrentUserInAudienceOf(AudienceLoader, String, Boolean) IsCurrentUserInAudienceOf(AudienceLoader, String, Boolean) IsCurrentUserInAudienceOf(AudienceLoader, String, Boolean)

This method will check whether current user's Audience membership belong to any audience as defined within audienceTextRepresentation. If does, return true, else return false. If there is any exception occured, this function will return false and log the exception, raise ShipAssert()

IsFilterActive() IsFilterActive() IsFilterActive()

Determines if the current ServerContext and UserProfileApplication have been set.

IsMemberOfAudience(String, Guid) IsMemberOfAudience(String, Guid) IsMemberOfAudience(String, Guid)

Determines whether a user is a member of a specified audience.

IsMemberOfAudience(String, String) IsMemberOfAudience(String, String) IsMemberOfAudience(String, String)

Determines whether a user is a member of a specified audience.

Resolve(String) Resolve(String) Resolve(String)
Search(String) Search(String) Search(String)
Search(String[]) Search(String[]) Search(String[])
ValidateIsIncludedFilter(String) ValidateIsIncludedFilter(String) ValidateIsIncludedFilter(String)

Verifies the validity of the specified string of globally unique identifiers (GUID)s for an audience.

Extension Methods

ToJson(Object) ToJson(Object) ToJson(Object)

Applies to