Share via


UserProfile.Item Property

Contains a specified property value.

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

Syntax

'Declaration
Public ReadOnly Default Property Item ( _
    strPropName As String _
) As UserProfileValueCollection
    Get
'Usage
Dim instance As UserProfile
Dim strPropName As String
Dim value As UserProfileValueCollection

value = instance(strPropName)
public UserProfileValueCollection this[
    string strPropName
] { get; }

Parameters

Property Value

Type: Microsoft.Office.Server.UserProfiles.UserProfileValueCollection
Object that contains the specified property value.
The Item property returns the value in the data type specified in the profile property schema PropertyCollection. When setting a property value, it is expected to be either the correct data type or a string that can be parsed to the correct data type. When passing a string, all properties must be formatted using the portal site's culture settings except for dates, which must be formatted using the invariant culture.

Remarks

If the property is a unique identifier property and if this property is imported from Microsoft Active Directory directory service, the return object could be Byte[] instead of Sytem.GUID.

Examples

The following code example shows how to retrieve the unique identifier property:

[Visual Basic]

      Public Sub UserProfileSample() 
         '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 upm As New UserProfileManager(pc)          'create user sample          Dim sAccount As String = "mydomain\myalias"          If Not upm.UserExists(sAccount) Then             upm.CreateUserProfile(sAccount)          End If          'to set prop values on user profile          Dim u As UserProfile = upm.GetUserProfile(sAccount)          Dim sPropName As String = "PreferredName"          u(sPropName) = sAccount          u.Commit()           'remove user profile sample          upm.RemoveUserProfile(sAccount)       End Sub 'UserProfileSample         Public Sub CreatePersonalSiteSample()          '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 upm As New UserProfileManager(pc)          Dim sAccount As String = "mydomain\myalias"          Dim u As UserProfile = upm.GetUserProfile(sAccount)          u.CreatePersonalSite()          Dim mysite As SPSite = u.PersonalSite          Dim myurl As String = u.PersonalUrl       End Sub 'CreatePersonalSiteSample

[C#]

UserProfileManager upm = new UserProfileManager(); 
UserProfile user = upm.GetUserProfile("domain\user"); System.Guid guidAUserProperty = GetGUIDProperty(user["AGuidProperty"]);  System.Guid GetGUIDProperty(object objPropValue) {    if (objPropValue is System.Guid)          return (Guid) objPropValue;    else if (objPropValue is byte[])          return new Guid((byte[]) objPropValue);    else throw new ArgumentException("...");     return Guid.Empty; }

See Also

Reference

UserProfile Class

UserProfile Members

Microsoft.Office.Server.UserProfiles Namespace