分類的複数値プロパティを作成する
最終更新日: 2010年4月14日
適用対象: SharePoint Server 2010
Microsoft SharePoint Server 2010 では、ユーザー プロファイルのプロパティを、使用可能な値のリストに制約を加える分類用語セットに結び付けることができます。複数の値を持つ分類プロパティを作成することによって、プロパティと選択肢リストを関連付けることができます。
分類と用語セットを作成し、使用する方法については、「エンタープライズ メタデータ管理の概要 (Microsoft SharePoint Server 2010 の開発者向け)」を参照してください。このトピックのコード サンプルで使用している用語セットを作成する方法を示すコード サンプルについては、前述のトピックの「コード サンプル: 分類の作成およびコミット、ラベルの追加、および用語の削除」を参照してください。
次のコード例は、複数の値を持つ分類プロパティを定義する方法を示しています。コード例を実行する前に、servername を実際の値に置き換えてください。また、Microsoft Visual Studio プロジェクトで、以下のアセンブリへの参照を追加してください。
Microsoft.Office.Server
Microsoft.Office.Server.UserProfiles
Microsoft.SharePoint
Microsoft.SharePoint.Taxonomy
System.Web
例
using System;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Taxonomy;
namespace UserProfilesOMApp
{
class Program
{
static void Main(string[] args)
{
// Code example adds a new multi value property named Hobbies.
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 = "Hobbies";
cp.DisplayName = "Hobbies";
cp.Type = "String (Multi Value)";
cp.IsMultivalued = true;
// Set the TermSet.
TaxonomySession taxonomySession = new TaxonomySession(site);
TermStore termStore = taxonomySession.TermStores["Managed Metadata Service"];
Group group = termStore.Groups["Group1"];
TermSet termSet = group.TermSets["TermSet1"];
cp.TermSet = termSet;
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();
}
}
}
}
}