ユーザー プロファイル プロパティを作成および編集する
最終更新日: 2010年7月20日
適用対象: SharePoint Server 2010
ユーザー プロファイル プロパティは、ユーザーに関する個人情報を説明するユーザー プロファイルに添付された名前と値のペアです。プロファイル ストアにはユーザー プロファイル プロパティ情報のリストが含まれます。この情報は、ユーザー アカウントが含まれるディレクトリからインポートすることによって取得されるか、ユーザー プロファイル ストアにアカウント情報を入力することによって手動で取得されます。既定では、Microsoft SharePoint Server 2010 では Active Directory ディレクトリ サービス、LDAP サーバー、ビジネス データ カタログからインポートできます。
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.Office.Server;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using System.Web;
namespace UserProfilesOMApp
{
class Program
{
static void Main(string[] args)
{
//Code example adds a new property called Marital Status.
using (SPSite site = new SPSite("https://servername"))
{
SPServiceContext context = SPServiceContext.GetContext(site);
UserProfileConfigManager upcm = new UserProfileConfigManager(context);
try
{
ProfilePropertyManager ppm = upcm.ProfilePropertyManager;
// create core property
CorePropertyManager cpm = ppm.GetCoreProperties();
CoreProperty cp = cpm.Create(false);
cp.Name = "MaritalStatus";
cp.DisplayName = "Marital Status";
cp.Type = PropertyDataType.StringSingleValue;
cp.Length = 100;
cpm.Add(cp);
// create profile type property
ProfileTypePropertyManager ptpm = ppm.GetProfileTypeProperties(ProfileType.User);
ProfileTypeProperty ptp = ptpm.Create(cp);
ptpm.Add(ptp);
// create profile subtype property
ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);
ProfileSubtype ps = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));
ProfileSubtypePropertyManager pspm = ps.Properties;
ProfileSubtypeProperty psp = pspm.Create(ptp);
psp.PrivacyPolicy = PrivacyPolicy.OptIn;
psp.DefaultPrivacy = Privacy.Organization;
pspm.Add(psp);
}
catch (DuplicateEntryException e)
{
Console.WriteLine(e.Message);
Console.Read();
}
catch (System.Exception e2)
{
Console.WriteLine(e2.Message);
Console.Read();
}
}
}
}
}