Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top