Which code segment should you use?

You are creating a Microsoft Office SharePoint Server 2007 site.

The site has five audiences. A user might belong to more than one of the five audiences.

You need to obtain a list of audience names for the current user.

Which code segment should you use?

You are creating a Microsoft Office SharePoint Server 2007 site.

The site has five audiences. A user might belong to more than one of the five audiences.

You need to obtain a list of audience names for the current user.

Which code segment should you use?

A.
private void ListAudienceNames()
{

AudienceLoader al = AudienceLoader.GetAudienceLoader();
AudienceManager am = am.CurrentServerContext;
ArrayList audiences = al.GetUserAudienceIDs(true);
foreach (object audience in audiences)
{
Audience a = am.Audiences[(Guid)audience];
System.Web.HttpContext.Current.Response.Write
(“Audience: ” + audience.ToString());
}

}

B.
private void ListAudienceNames()
{

using (SPWeb web = SPWeb.OriginalBaseUrl )
{
SPUser user = web.CurrentUser;
AudienceManager am = am.CurrentServerContext;
AudienceCollection audiences = am.Audiences;
foreach (Audience a in audiences)
{
if (a.IsMember(user.LoginName))
System.Web.HttpContext.Current.Response.Write
(“Audience: ” + AudienceName);
}
}

}

C.
private void ListAudienceNames()
{

string user = WindowsIdentity.GetCurrent().Name;
SPWeb web = SPWeb.OriginalBaseUrl;
AudienceManager am = am.CurrentServerContext;
ArrayList audList = am.GetUserAudienceIDs(user, false, web);
foreach (object obj in audList)
{
Audience a = (Audience)obj;
System.Web.HttpContext.Current.Response.Write
(“Audience: ” + a.AudienceName);
}

}

D.
private void ListAudienceNames()
{

using (SPWeb web = SPWeb.OriginalBaseUrl )
{
string user = web.CurrentUser.Name;
AudienceManager am = am.CurrentServerContext;
foreach (Audience a in am.Audiences)
{
if (am.IsMemberOfAudience(user, a.AudienceName))
System.Web.HttpContext.Current.Response.Write
(“Audience: ” + a.AudienceName);
}
}

}



Leave a Reply 0

Your email address will not be published. Required fields are marked *