Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

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();
share|improve this answer
    
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

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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