Audience Class

Represents an audience on a Microsoft Office SharePoint Server 2007 site.

Inheritance Hierarchy

System.Object
  Microsoft.Office.Server.Audience.Audience

Namespace:  Microsoft.Office.Server.Audience
Assembly:  Microsoft.Office.Server (in Microsoft.Office.Server.dll)

Syntax

'Declaration
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
Public Class Audience
'Usage
Dim instance As Audience
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
public class Audience

Remarks

Audiences are groups of users determined by their memberships in Microsoft Exchange distribution lists (DL) or SharePoint groups, or by rules configured by a portal administrator. For example, you could set up new employees, executives, salespeople, or people from a specified city as audiences. In SharePoint Server 2007, you can base the audience rules on information in the user profile, on membership in an Active Directory directory service security group or an Exchange distribution list, or on the organization's reporting structure (if this information is kept in Active Directory).

Audiences allow organizations to target content to users based on their job or task, as defined by their membership in a SharePoint group or distribution list, by the organizational reporting structure, or by the public properties in their user profiles.

Microsoft Office SharePoint Portal Server 2003 supported only rules-based compiled audiences. Office SharePoint Server 2007 supports targeting based on audience, SharePoint groups, and DL memberships. In addition, Office SharePoint Server 2007 provides the ability to target to the list-item level, rather than just to the list level.

Examples

This code example shows how to create a rules-based audience to which you can target content.

Note

The audience is only created here; it is not compiled, and rules have not been added. You can add rules by using the user interface or the object model, and then compile the audience by using the user interface. Compiling audiences is not supported in the object model.

Replace servername and other strings with actual values before running the code example. Also add the following references in your Microsoft Visual Studio project:

  • Microsoft.Office.Server

  • Microsoft.SharePoint

  • System.Web

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;

namespace AudienceConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                using (SPSite site = new SPSite("https://servername"))
                {
                    ServerContext context = ServerContext.GetContext(site);
                    AudienceManager audManager = new AudienceManager(context);

                    AudienceCollection ac = audManager.Audiences;
                    Audience a = null;
                    string sAudName = "Customer Connection";
                    string sDescription = "Members of the Customer Connection v-team";

                    try
                    {
                        a = ac.Create(sAudName, sDescription);
                    }
                    catch (AudienceDuplicateNameException e)
                    {
                        //Your exception handling code here
                    }
                    catch (AudienceException e1)
                    {
                        //Your exception handling code here
                    }
                }

            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.ToString());
                Console.Read();
            }

        }
    }
}

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

Audience Members

Microsoft.Office.Server.Audience Namespace