Well i found a workaround for this, i was experiencing an issue when trying to check if the current user was a memeber of the audience for a specific publishing page and what the name of that audience was. Here is the workaround i came up with.
// Run through the pages building the list items
foreach (SPListItem li in pages)
{
// Get a reference to the publishing page
PublishingPage p = PublishingPage.GetPublishingPage(li);
// Make sure the page has been approved
if (li.ModerationInformation.Status == SPModerationStatusType.Approved)
{
// Check if this page has an audience
if (string.IsNullOrEmpty(p.Audience))
// Add to everyone list
else
{
// Split the audiences
string[] Audiences = p.Audience.Split(';');
// Check each audience to see if this user can see it
foreach (string audPart in Audiences)
{
AudienceManager audienceManager = new AudienceManager();
// Get a reference to the audience
// IsGuid is an extenstion method i wrtoe
if (audPart.IsGuid())
{
if (audienceManager.Audiences.AudienceExist(new Guid(audPart)))
aud = audienceManager.Audiences[new Guid(audPart)];
}
else
{
if (audienceManager.Audiences.AudienceExist(audPart))
aud = audienceManager.Audiences[audPart];
}
// Ensure we have a reference to the audience
if (aud != null)
{
// store the item in the temp variables
switch (aud.AudienceName)
{
case "All site users":
// Add to everyone list
break;
case "Some List":
if (audienceManager.IsMemberOfAudience(web.CurrentUser.LoginName, aud.AudienceID))
{
// Add to other list
}
break;
case "Other List":
if (audienceManager.IsMemberOfAudience(web.CurrentUser.LoginName, aud.AudienceID))
{
// Add to other list
}
break;
}
}
}
}
}
}
As you can see its really just a mater of checking if the audience exists by using AudienceManager.Audiences.AudienceExist and the getting a reference to it by just using the default accesor AudienceManager.Audiences[GUID];