以编程方式创建用户配置文件部分
-
16-10-2019 - |
题
我试图以编程方式创建一个新的用户配置文件部分,但没有成功。问题在于 输入属性类的属性.
当我为此指定诸如“部分”之类的值时,我会收到异常 数据类型不可用于部分. 。当我不指定值时,我会收到异常 userProfilepropertySettsings对象必须具有“类型”的值集.
这是代码:
var userProfileConfigManager = new UserProfileConfigManager(ServerContext.GetContext(site));
var propertyCollection = userProfileConfigManager.GetPropertiesWithSection();
var newProperty = propertyCollection.Create(true);
newProperty.Name = "NewSection";
newProperty.DisplayName = "NewSection";
newProperty.Type = "section"; // or not set
newProperty.IsUserEditable = false;
newProperty.Length = 0;
newProperty.DefaultPrivacy = 0;
newProperty.PrivacyPolicy = 0;
newProperty.IsSearchable = false;
newProperty.IsVisibleOnEditor = false;
newProperty.IsVisibleOnViewer = false;
newProperty.Separator = MultiValueSeparator.Unknown;
newProperty.Commit();
有任何想法吗?
解决方案
我的错误 - 第二个例外是由于过度狂热的输入检查!但是,代码也不正确。它应该阅读:
var userProfileConfigManager = new UserProfileConfigManager(ServerContext.GetContext(site));
var propertyCollection = userProfileConfigManager.GetPropertiesWithSection();
var newProperty = propertyCollection.Create(true);
newProperty.Name = "NewSection";
newProperty.DisplayName = "NewSection";
newProperty.Commit();
其他提示
设定本节的顺序也是一个好主意:
// order being the absolute position you want to place section in property list
propertyCollection.SetDisplayOrderBySectionName(newProperty.Name,order);
propertyCollection.CommitDisplayOrder();
这通常就是为什么我首先以编程方式执行此操作的原因,因此我不必在SSP中的用户配置文件属性映射列表中单击/下降1000次:-) - Anders Rask 0 secs of
Hth Anders Rask