[方法] 2 つのユーザー プロファイル間の共通点を取得する
ユーザーが別のユーザーのプロファイル ページにアクセスした場合、Microsoft Office SharePoint Server 2007 では、2 人のユーザー間のすべての共通点が表示されます。その例を次に示します。
両者に共通の上司
両者が属する配布リストと Windows SharePoint Services 3.0 サイト
両者に共通の仕事仲間
オブジェクト モデルを使用して、2 つのユーザー プロファイル インスタンス間の共通点を見つけることができます。次のコード例は、指定したユーザーと現在ログオンしているユーザーの共通メンバシップおよび共通の上司を見つける方法を示しています。
このコード例を実行する前に、servername, domainname、および username を実際の値に置き換えてください。また、Microsoft Visual Studio プロジェクトで以下の参照を追加してください。
Microsoft.Office.Server
Microsoft.SharePoint
System.Web
例
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using System.Web;
namespace UserProfilesApp
{
class Program
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("https://servername"))
{
ServerContext context = ServerContext.GetContext(site);
UserProfileManager profileManager =
new UserProfileManager(context);
string sAccount = "domainname\\username";
UserProfile u =
profileManager.GetUserProfile(sAccount);
//Get common memberships
MemberGroup[] mem =
u.Memberships.GetCommonMemberships();
Console.WriteLine(mem[0].DisplayName);
//Get common manager
UserProfile manager = u.GetCommonManager();
Console.WriteLine(manager["DisplayName"]);
}
}
}
}