Export (0) Print
Expand All

Property Class

Represents the definition for a user profile property.

System.Object
  Microsoft.Office.Server.UserProfiles.Property

Namespace:  Microsoft.Office.Server.UserProfiles
Assembly:  Microsoft.Office.Server (in Microsoft.Office.Server.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.

Because of the nature of the Section object, the following properties are not applicable: Type, DisplayName, IsUserEditable, IsAdminEditable, Length, IsPrivate, IsAlias, IsVisibleOnViewer. If you try to set a value, an UPUpdateReadOnlyFieldException is thrown.

For regular properties, the Name property can only be set at creation time. No further update is allowed. If there is an attempt to update, an UPUpdateReadOnlyFieldException is thrown. The Name property is used to compose the URI of the property. Therefore the name must be a valid URI schema name, otherwise an UPInvalidValueException is thrown.

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

[Visual Basic]

      'sample uses the following classes: UserProfileConfigManager,

      'PropertyDataTypeCollection, PropertyDataType,
      'PropertyCollection, Property, PropertyConstants
      'PropertyMapCollection, PropertyMap
      Public Sub PropertyTypeAndMappingSample()
         'get portal site context from topology
         Dim strUrl As String = "http://SampleName"
         Dim tm As New TopologyManager()
         Dim ps As PortalSite = tm.PortalSites(New Uri(strUrl))
         Dim pc As PortalContext = PortalApplication.GetContext(ps)

         'initialize user profile config manager object
         Dim upcm As New UserProfileConfigManager(pc)

         'sample to get a property type "URL"
         Dim pdtc As PropertyDataTypeCollection = upcm.GetPropertyDataTypes()
         Dim ptype As PropertyDataType = Nothing
         Dim enumType As IEnumerator = pdtc.GetEnumerator()
         While enumType.MoveNext()
            ptype = CType(enumType.Current, PropertyDataType)
            If ptype.Name.Equals("string") Then
               Exit While
            End If
         End While
         'sample to create a new custom property of type URL
         Dim pcol As PropertyCollection = upcm.GetProperties()
         Dim prop As [Property] = pcol.Create(False)
         prop.Name = "division"
         prop.DisplayName = "my custom division"
         prop.Type = ptype.Name
         prop.Length = ptype.MaxCharCount
         prop.IsPrivate = False
         prop.IsUserEditable = True
         prop.IsVisibleOnEditor = True
         prop.IsVisibleOnViewer = True
         prop.IsAlias = False
         pcol.Add(prop)
         pcol.SetDisplayOrderByPropertyName(prop.Name, 1)
         pcol.CommitDisplayOrder()

         'edit property sample
         Dim ptitle As [Property] = pcol.GetPropertyByName(PropertyConstants.Title)
         ' or get property by URI
         ptitle = pcol.GetPropertyByURI([Property].URI_Title)
         ptitle.DisplayName = "Designation"
         ptitle.Commit()

         'property map sample
         Dim ds As DataSource = upcm.GetDataSource()
         Dim pmc As PropertyMapCollection = ds.PropertyMapping
         pmc.Add(prop.Name, "division")
         'get arraylist of invalid mappings
         Dim invmap As ArrayList = pmc.VerifyMapping(False)
         'remove current mapping if invalid
         Dim pm As PropertyMap
         For Each pm In  invmap
            If pm.PropName = prop.Name Then
               pmc.Remove(pm.PropName)
            End If
         Next pm

         'remove property sample
         pcol.RemovePropertyByName("division")
      End Sub 'PropertyTypeAndMappingSample
//sample uses the following classes: UserProfileConfigManager,

//PropertyDataTypeCollection, PropertyDataType,
//PropertyCollection, Property, PropertyConstants
//PropertyMapCollection, PropertyMap
public void PropertyTypeAndMappingSample()
{
//get portal site context from topology
string strUrl = "http://SampleName";
TopologyManager tm = new TopologyManager();
PortalSite ps = tm.PortalSites[new Uri(strUrl)];
PortalContext pc = PortalApplication.GetContext(ps);

//initialize user profile config manager object
UserProfileConfigManager upcm = new UserProfileConfigManager(pc);

//sample to get a property type "URL"
PropertyDataTypeCollection pdtc = upcm.GetPropertyDataTypes();
PropertyDataType ptype = null;
IEnumerator enumType = pdtc.GetEnumerator();
while (enumType.MoveNext())
{
ptype = (PropertyDataType)enumType.Current;
if (ptype.Name.Equals("string")) break;
}

//sample to create a new custom property of type URL
PropertyCollection pcol = upcm.GetProperties();
Property prop = pcol.Create(false);
prop.Name = "division";
prop.DisplayName = "my custom division";
prop.Type = ptype.Name;
prop.Length = ptype.MaxCharCount;
prop.IsPrivate = false;
prop.IsUserEditable = true;
prop.IsVisibleOnEditor = true;
prop.IsVisibleOnViewer = true;
prop.IsAlias = false;
pcol.Add(prop);
pcol.SetDisplayOrderByPropertyName(prop.Name, 1);
pcol.CommitDisplayOrder();

//edit property sample
Property ptitle = pcol.GetPropertyByName(PropertyConstants.Title);
// or get property by URI
ptitle = pcol.GetPropertyByURI(Property.URI_Title);
ptitle.DisplayName = "Designation";
ptitle.Commit();

//property map sample
DataSource ds = upcm.GetDataSource();
PropertyMapCollection pmc = ds.PropertyMapping;
pmc.Add(prop.Name, "division");
//get arraylist of invalid mappings
ArrayList invmap = pmc.VerifyMapping(false);
//remove current mapping if invalid
foreach(PropertyMap pm in invmap)
{
if (pm.PropName == prop.Name)
{
pmc.Remove(pm.PropName);
}
}

//remove property sample
pcol.RemovePropertyByName("division");
}

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

Community Additions

ADD
Show:
© 2015 Microsoft