Export (0) Print
Expand All

How to: Determine Members of an Audience

This example shows how to determine the members of an audience.

Replace servername and other placeholder strings with actual values before using this example. Also add the following references to your Microsoft Visual Studio project:

  • Microsoft.Office.Server

  • Microsoft.SharePoint

  • System.Web

Example

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;
using System.Collections;

namespace AudienceConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                using (SPSite site = new SPSite("http://servername"))
                {
                    ServerContext context = ServerContext.GetContext(site);
                    AudienceManager AudMgr = new AudienceManager(context);
                    try
                    {
                        ArrayList memarray = AudMgr.Audiences["Customer Connection Team"].GetMembership();

                        foreach (UserInfo o in memarray)
                        {
                            Console.WriteLine(o.NTName);
                        }
                        Console.Read();
                    }
                    catch (AudienceException e)
                    {
                        //Your exception handling code here
                    }
                }


            }


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

        }
    }

}

See Also

Community Additions

ADD
Show:
© 2015 Microsoft