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 (in Microsoft.Office.Server.dll)
Syntax
'Declaration
<SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
Public Class AudienceManager _
Implements IRuntimeFilter2
'Usage
Dim instance As AudienceManager
[SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
public class AudienceManager : IRuntimeFilter2
Remarks
The AudienceManager class is the entry point for the audience feature in Microsoft Office SharePoint Server 2007. 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. 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 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"))
{
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)
{
//Your exception handling code here
}
catch (AudienceException e1)
{
//Your exception handling code here
}
}
}
catch (Exception exception)
{
Console.WriteLine(exception.ToString());
Console.Read();
}
}
}
}
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.