How to: Determine Members of an Audience
Applies to: SharePoint Server 2010
This example shows how to determine the members of an audience.
Replace servername and other placeholder strings with actual values before using this example. Also add the following references to your Microsoft Visual Studio project:
Microsoft.Office.Server
Microsoft.Office.Server.UserProfiles
Microsoft.SharePoint
System.Web
Example
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;
using System.Collections;
namespace AudienceConsoleApp
{
class Program
{
static void Main(string[] args)
{
try
{
using (SPSite site = new SPSite("https://servername"))
{
SPServiceContext context = SPServiceContext.GetContext(site);
AudienceManager AudMgr = new AudienceManager(context);
try
{
ArrayList memarray = AudMgr.Audiences["Customer Connection Team"].GetMembership();
foreach (UserInfo o in memarray)
{
Console.WriteLine(o.NTName);
}
Console.Read();
}
catch (AudienceException e)
{
//Your exception handling code here
}
}
}
catch (Exception exception)
{
Console.WriteLine(exception.ToString());
Console.Read();
}
}
}
}