PropertyMap Class

Represents a property mapping that defines property mapping between the user profile and the import data source—Microsoft Active Directory directory service.

Inheritance Hierarchy

System.Object
  Microsoft.Office.Server.UserProfiles.PropertyMap

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

Syntax

'Declaration
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
Public Class PropertyMap
'Usage
Dim instance As PropertyMap
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
public class PropertyMap

Remarks

Only a one-on-one relationship is allowed. If there is an attempt to map more than one user profile property to one Active Directory property, or map one user profile property to more than one Active Directory property, an UPDuplicateEntryException is thrown.

Examples

The following code example shows the use of the PropertyMap 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");
}

Thread Safety

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

See Also

Reference

PropertyMap Members

Microsoft.Office.Server.UserProfiles Namespace