1

I'm attempting to create a new user profile section programmatically but without success. The problem is with the Type property of the Property class.

When I specify a value such as "section" for this, I receive the exception Data Type is not available for section. When I don't specify a value, I receive the exception UserProfilePropertySettings object must have a value set for 'Type'.

Here's the code:

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();

Any ideas?

0

My mistake - the second exception was my own due to overzealous input checking! However the code was also incorrect. It should read:

var userProfileConfigManager = new UserProfileConfigManager(ServerContext.GetContext(site));

var propertyCollection = userProfileConfigManager.GetPropertiesWithSection();

var newProperty = propertyCollection.Create(true);
newProperty.Name = "NewSection";
newProperty.DisplayName = "NewSection";

newProperty.Commit();
  • so did you solve it? If so the moderator would probably ask you to mark as answered ;-) – Anders Rask Dec 24 '09 at 9:46
  • Have to wait 48 hours if answering own question :-) – Alex Angas Dec 25 '09 at 2:44
0

Its also a good idea to set the order of the section:

// order being the absolute position you want to place section in property list 
propertyCollection.SetDisplayOrderBySectionName(newProperty.Name,order);
propertyCollection.CommitDisplayOrder();

this is usually why i do this programmatically in the first place, so i dont have to click up/down 1000 times inside the user profile property mapping list in SSP :-) – Anders Rask 0 secs ago

hth Anders Rask

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.