メンバシップを作成する
最終更新日: 2010年1月27日
適用対象: SharePoint Server 2010
Microsoft SharePoint Server 2010 では、配布リスト (DL) メンバーシップと Windows SharePoint Services サイト メンバーシップの 2 種類のメンバーシップがサポートされます。DL メンバーシップ情報は Active Directory ディレクトリ サービスから取得され、Windows SharePoint Services サイト メンバーシップ情報は SharePoint サイトからメンバーシップ情報を得ることによって取得されます。プロファイル ページと呼ばれる、ユーザーの個人用サイトのパブリック ページには、ユーザーのメンバーシップのほか、ユーザーと表示側ユーザーが共通して持つメンバーシップなどの情報が表示されます。
ユーザー プロファイル オブジェクト モデルは、新しいメンバシップ機能をサポートするクラスおよびメソッドを追加します。ユーザー プロファイル オブジェクト モデルの新しいクラスおよびメソッドでは、次の操作がサポートされます。
ユーザーのメンバシップを取得する
ユーザーのメンバシップのプライバシー設定を設定する
2 ユーザー間の共通メンバシップを取得する
メンバ グループを列挙する
新しいメンバシップの種類を拡張し、オブジェクト モデルで新しいメンバシップを追加できるようにする
Membership は、ユーザー プロファイル オブジェクト モデルのファースト クラス オブジェクトです。UserProfile オブジェクトからメンバシップにアクセスできます。
MemberGroup オブジェクトは、DL または Windows SharePoint Services サイト、あるいはオブジェクト モデルを使用して作成するその他の新しいメンバ グループを定義します。定義する URL プロパティは、DL の場合はアーカイブ場所 (mailto: リンク) を表し、MemberGroup オブジェクトの場合は Windows SharePoint Services サイトの URL を表します。SourceReference プロパティは、Active Directory からの DL の DirectoryEntry、あるいは MemberGroup に応じて SPWeb または SPSite オブジェクトを返します。
UserProfileManager クラスは、メンバ グループ定義を返して新しいメンバシップの種類を作成するメソッドを追加します。
次の例では、新しいメンバ グループを作成し、新しく作成したグループにメンバを追加します。このコード例を使用する前に、servername、domainname、username、およびその他のプレースホルダを実際の値に置き換えてください。また、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.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"))
{
SPServiceContext context =
SPServiceContext.GetContext(site);
UserProfileManager profileManager =
new UserProfileManager(context);
//Create a member group
MemberGroup newGroup =
profileManager.GetMemberGroups().
CreateMemberGroup(PrivacyPolicyIdConstants.
MembershipsFromDistributionLists,
"Customer Connection Team","Customer Connection VTeam","Customer Connection","http://example","abcd");
//Create a membership
string sAccount = "domainname\\username";
UserProfile u = profileManager.GetUserProfile(sAccount);
u.Memberships.Create(newGroup,
MembershipGroupType.UserSpecified,
"Customer Connection Team", Privacy.Organization);
}
}
}
}