Share via


How to: Target List Items to an Audience

By using Web Parts that recognize audience membership, you can target items or links in a list to one or more audiences, so that only members of those audiences view the targeted items within the Web Parts. For example, in a default area called Human Resources, a site administrator or the manager of that area may choose to add a news item within the News Web Part. This item could be targeted to an audience composed of all new employees, directing them to the New Employee Benefits site.

The following example shows you how to target a list item to an audience.

Example

   AudienceLoader audienceLoader = AudienceLoader.GetAudienceLoader();
   foreach (SPListItem listItem in list.Items)
   {
      // get roles the list item is targeted to
     string audienceFieldValue = (string)listItem[k_AudienceColumn];

      // quickly check if the user belongs to any of those roles
     if (AudienceManager.IsCurrentUserInAudienceOf(audienceLoader,
        audienceFieldValue,
        false))
                {
                    // is a member
                }
                else
                {
                    // not a member
                }
            }

See Also

Concepts

Audience Object Model Overview

Other Resources

Targeting Content Using Audiences