AudienceManager Class
Represents the entry point for the audience classes.
Inheritance Hierarchy
System.Object
Microsoft.Office.Server.Audience.AudienceManager
Namespace: Microsoft.Office.Server.Audience
Assembly: Microsoft.Office.Server.UserProfiles (in Microsoft.Office.Server.UserProfiles.dll)
Syntax
'Declaration
<SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
Public Class AudienceManager _
Implements IRuntimeFilter2, IRuntimeFilter
'Usage
Dim instance As AudienceManager
[SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
public class AudienceManager : IRuntimeFilter2,
IRuntimeFilter
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.
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. You can also compile audiences by using the AudienceJob class.
Replace servername and other strings with actual values before running the code example. Also add the following references in your Microsoft 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"))
{
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("https://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
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.