Share via


PropertyDataType Class

Represents the definition for the data types of a profile property.

Inheritance Hierarchy

System.Object
  Microsoft.Office.Server.UserProfiles.PropertyDataType

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

Syntax

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

Examples

The following code example shows how to use the PropertyDataType class.

[Visual Basic]

' This 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)

    ' The sample gets a property of 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
    ' The sample creates 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 the 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()

    ' A 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 not valid.
    Dim pm As PropertyMap
    For Each pm In  invmap
        If pm.PropName = prop.Name Then
            pmc.Remove(pm.PropName)
        End If
    Next pm

        ' Remove the property sample.
        pcol.RemovePropertyByName("division")
    End Sub 'PropertyTypeAndMappingSample
// This 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);

        // Iinitialize a user profile config manager object.
        UserProfileConfigManager upcm = new 
            UserProfileConfigManager(pc);

        // The sample gets a property of 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;
        }

        // The sample creates 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 the property sample,
        Property ptitle = 
            pcol.GetPropertyByName(PropertyConstants.Title);
        // or get property by URI.
        ptitle = pcol.GetPropertyByURI(Property.URI_Title);
        ptitle.DisplayName = "Designation";
        ptitle.Commit();

        // A 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 the current mapping if not valid.
        foreach(PropertyMap pm in invmap)
        {
            if (pm.PropName == prop.Name)
            {
            pmc.Remove(pm.PropName);
            }
        }

        // Remove the 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

PropertyDataType Members

Microsoft.Office.Server.UserProfiles Namespace