如何:确定访问群体的成员
上次修改时间: 2010年1月27日
适用范围: SharePoint Server 2010
本示例将演示如何确定访问群体的成员。
使用本示例之前,请将 servername 和其他占位符字符串替换为实际的值。另外向您的 Microsoft Visual Studio 项目添加以下引用:
Microsoft.Office.Server
Microsoft.Office.Server.UserProfiles
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;
using System.Collections;
namespace AudienceConsoleApp
{
class Program
{
static void Main(string[] args)
{
try
{
using (SPSite site = new SPSite("https://servername"))
{
SPServiceContext context = SPServiceContext.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();
}
}
}
}