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 would like to know how to change the display order of the out of the box user profile properties using sharepoint object model ?

I would like to move OOTB properties into my custom section.

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Take a look at Property Class

There are two types of user profile properties:

Regular - Defines the property data type and the corresponding user profile flags.

Section - Property that serves as a separator for user interface grouping purposes.

In order to move properties 'into' section you just need to reorder them.

I am providing a little example on how to create new section and then move few OOTB properties 'into' it by simple reorder. Check code comments for clarification.

var customSectionDisplayName = "My New CustomSection";
// For 'internal' name remove whitespace
var customSectionName = customSectionDisplayName.Replace(" ", "");

using (SPSite site = new SPSite("http://mycoolsite"))
{
    SPServiceContext context = SPServiceContext.GetContext(site);
    // There are just 'few' managers we need
    UserProfileConfigManager upcm = new UserProfileConfigManager(context);
    ProfilePropertyManager ppm = upcm.ProfilePropertyManager;
    CorePropertyManager cpm = ppm.GetCoreProperties();
    ProfileTypePropertyManager ptpm = ppm.GetProfileTypeProperties(ProfileType.User);
    ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);
    ProfileSubtype ps = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));
    ProfileSubtypePropertyManager pspm = ps.Properties;

    // Check if section already exist
    if(cpm.GetSectionByName(customSectionName) == null)
    {
        // Add new section
        CoreProperty section = cpm.Create(true);
        section.Name = customSectionName;
        section.DisplayName = customSectionDisplayName;
        section.Commit();
        ProfileTypeProperty profileSection = ptpm.Create(section);
        profileSection.Commit();
        ProfileSubtypeProperty profileSubSection = pspm.Create(profileSection);
        profileSubSection.DefaultPrivacy = Privacy.Private;
        profileSubSection.Commit();
    }

    // In default configuration Custom Properties are the last section 
    // with display order value of 5500
    // Let's move our new section to the end
    pspm.SetDisplayOrderBySectionName(customSectionName, 6000);
    pspm.CommitDisplayOrder();

    // And now let's move some core properties 
    // Work Email ...
    pspm.SetDisplayOrderByPropertyName(PropertyConstants.WorkEmail, 6100);
    // ... and Work Phone 
    pspm.SetDisplayOrderByPropertyName(PropertyConstants.WorkPhone, 6200);
    pspm.CommitDisplayOrder();
}
share|improve this answer
    
Thats awsome... It works great... Thank you. –  Share Sep 16 '11 at 14:40
add comment

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.