複数値プロパティを作成する
最終更新日: 2010年3月22日
適用対象: SharePoint Server 2010
プロパティで複数の値がサポートされるようになりました。この改善点は、さまざまなシナリオで利用できます。たとえば、ユーザーの関心事や専門分野のように通常は複数の値を持つプロパティを定義する場合などです。
オブジェクト モデルの IsMultiValued パラメータは、プロパティが複数値プロパティであるかどうかを示します。ただし、プロパティのデータ型と同様に、このパラメータは、いったん設定した後は変更できません。
オブジェクト モデルでは、複数値プロパティの複数の値は ArrayList オブジェクトとして返されます。コレクション内の値の順序は、更新順序と同じです。例については、「[方法] 複数の値を持つプロパティに複数の値を設定する」を参照してください。
複数値プロパティもインデックス付けを行うことができます。現在、SharePoint Server 2010 のSharePoint エンタープライズ検索では、複数値プロパティの Contains 句および Equals 句がサポートされています。
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 Published Papers.
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 = "Published Papers";
cp.DisplayName = "Published Papers";
cp.Type = PropertyDataType.StringMultiValue;
cp.Length = 100;
cp.IsMultivalued = true;
cpm.Add(cp);
// create profile type property
ProfileTypePropertyManager ptpm = ppm.GetProfileTypeProperties(ProfileType.User);
ProfileTypeProperty ptp = ptpm.Create(cp);
ptp.IsVisibleOnEditor = true;
ptp.IsVisibleOnViewer = true;
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.IsUserEditable = true;
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();
}
}
}
}
}