PropertyMapCollection Class
Represents a collection of PropertyMap objects. This class stores all property mappings for the data source.
Inheritance Hierarchy
System.Object
Microsoft.Office.Server.UserProfiles.PropertyMapCollection
Namespace: Microsoft.Office.Server.UserProfiles
Assembly: Microsoft.Office.Server (in Microsoft.Office.Server.dll)
Syntax
'Declaration
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel := True)> _
Public Class PropertyMapCollection _
Implements ICollection
'Usage
Dim instance As PropertyMapCollection
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel = true)]
public class PropertyMapCollection : ICollection
Examples
The following code example shows the use of the PropertyMapCollection 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
[C#]
//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.