Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Property class

Represents the definition for a user profile property.


Namespace:  Microsoft.Office.Server.UserProfiles
Assembly:  Microsoft.Office.Server.UserProfiles (in Microsoft.Office.Server.UserProfiles.dll)

[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public class Property : IPrivacyPolicyItem

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 Microsoft SharePoint Server 2010, this type delegates most of its methods to CoreProperty, ProfileTypeProperty, and ProfileSubtypeProperty. Exceptions are thrown from these classes.

The following code example shows the use of the Property class.

static public void PropertyTypeAndMappingSample()
  using (SPSite site = new SPSite("site url"))
    SPServiceContext context = SPServiceContext.GetContext(site);
//Initialize user profile config manager object.
    UserProfileConfigManager upcm = new UserProfileConfigManager(context);
    ConnectionManager cm = upcm.ConnectionManager;
//Sample to get a property type.
    PropertyDataTypeCollection pdtc = upcm.GetPropertyDataTypes();
    PropertyDataType ptype = null;
    foreach (PropertyDataType datatype in pdtc)
      if (datatype.Name.Equals("string"))
        ptype = datatype;
//Sample to create a new custom property.
    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;
    CoreProperty coreProp = cpm.Create(false);
    coreProp.Name = "division";
    coreProp.DisplayName = "my custom division";
    coreProp.Type = ptype.Name;
    coreProp.Length = ptype.MaxCharCount;
    ProfileTypeProperty profileTypeProp = ptpm.Create(coreProp);
    profileTypeProp.IsVisibleOnEditor = true;
    profileTypeProp.IsVisibleOnViewer = true;
    ProfileSubtypeProperty profileSubTypeProp = pspm.Create(profileTypeProp);
    profileSubTypeProp.DefaultPrivacy = Privacy.Private;
    profileSubTypeProp.IsUserEditable = true;
    pspm.SetDisplayOrderByPropertyName(profileSubTypeProp.Name, 1);
//Edit property sample.
    CoreProperty ptitle = cpm.GetPropertyByName(PropertyConstants.Title);
// Or get property by URI.
    ptitle = cpm.GetPropertyByURI(Property.URI_Title);
    ptitle.DisplayName = "Designation";
//Property map sample.
    string connectionName = "Test Connection";
    Connection connection = cm[connectionName];
    PropertyMapCollection pmc = connection.PropertyMapping;
    pmc.AddNewMapping(ProfileType.User, profileSubTypeProp.Name, "division");
//Remove property sample.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
© 2015 Microsoft