Adding choices to existing UserProfile properties

When editing ChoiceList items of existing UserProfile properties you also need to increment the MaximumShown property. Otherwise the changes (neiter removal nor addition) will be saved when calling Commit().

This won’t work:


// Get the property from the UserProfileManager instance
Property property = userProfileManager.PropertiesWithSection.GetPropertyByName("MyExistingProperty")
// Remove old choice items
property.ChoiceList.Remove("Old Choice 1");
property.ChoiceList.Remove("Old Choice 2");
// Add new choice items
property.ChoiceList.Add("New Choice 1");
property.ChoiceList.Add("New Choice 2");
// Save the property
property.Commit();

This will work:


// Get the property from the UserProfileManager instance
Property property = userProfileManager.PropertiesWithSection.GetPropertyByName("MyExistingProperty")
// Remove old choice items
property.ChoiceList.Remove("Old Choice 1");
property.ChoiceList.Remove("Old Choice 2");
// Add new choice items
property.ChoiceList.Add("New Choice 1");
property.ChoiceList.Add("New Choice 2");
// Increase MaximumShown by the amount of properties that were added (ignore the number of properties removed)
property.MaximumShown += 2;
// Save the property
property.Commit();

See also: http://blogs.msdn.com/nishand/archive/2007/05/20/updating-userprofile-property-of-type-choicelist.aspx

Posted in .NET | Tagged , , , | Leave a comment

GUIDs in SharePoint Site Columns

As you know, SharePoint uses a lot of GUIDs. Usually it makes no difference if you include the accolades around the GUID, except when defining Site Columns. Of course, SharePoint doesn’t actually complain about the lack of accolades, not even when you reference your Site Column in a Content Type. It will just completely ignore the Site Column and not include it in the Content Type.

Wrong:



<ID="f35719f9-2c30-4a6b-9962-69b481139a02"
Name="FunctionCode"
DisplayName=""
Group="UserProfile Function History Columns"
Type="Text"
Required="false"
/>


Right:



<ID="{f35719f9-2c30-4a6b-9962-69b481139a02}"
Name="FunctionCode"
DisplayName=""
Group="UserProfile Function History Columns"
Type="Text"
Required="false"
/>


References to the Site Columns do not need to include the accolades. The following will still work:



<ID="f35719f9-2c30-4a6b-9962-69b481139a02"
Name="FunctionCode"
DisplayName=""
Required="false"
/>


Posted in .NET | Tagged , , | 2 Comments