Wednesday, September 17, 2008

Programatically getting the Audience Membership

Code:

using (SPSite spSite = new SPSite(@"http://localhost"))
{
ServerContext siteContext = ServerContext.GetContext(spSite);
AudienceManager amManager = new AudienceManager(siteContext);

string strName = "HR Department";
Audience oAudience = amManager.Audiences[strName];

ArrayList oAudienceMembers = oAudience.GetMembership();

foreach (UserInfo oUser in oAudienceMembers)
{
Console.WriteLine(oUser.PreferredName);
Console.WriteLine(oUser.NTName);
Console.WriteLine(oUser.Email);
}
}

0 comments: