There are quite a number of ways in which the Profile properties can be accessed once you have a UserInfo object for either the currently logged in user or another user. The Profile property of the UserInfo object exposes all of the "built-in" properties such as "Street" and "PostalCode" as public properties. Custom profile properties that you have defined can be returned by either indexing the Profile.ProfileProperties collection of ProfilePropertyDefinitions by ordinal or key name or through it's GetByName method. They may also be obtained by the GetPropertyValue method of the Profile object. Here are a few examples of code taken from a module I'm working on:
This first sample presents a drop-down list of DNN users matching the specified full name and fills in form fields with the selected user's address information:
Private Function LookupSubject(ByVal FullName As String) As Integer
Dim TotalRecords As Integer
Dim LastName As String
Dim FirstName As String
If Not String.IsNullOrEmpty(FullName) Then
'lookup subject name in DNN user database
Dim NameTokens() As String = FullName.Split(" "c)
If NameTokens.Length >= 2 Then
FirstName = NameTokens(0)
LastName = NameTokens(1)
Dim uc As New DotNetNuke.Entities.Users.UserController
Dim DNNUser As DotNetNuke.Entities.Users.UserInfo
Dim MatchedUsers As ArrayList = DotNetNuke.Entities.Users.UserController.GetUsersByProfileProperty(PortalId, "Lastname", LastName, 0, 10, TotalRecords)
Select Case MatchedUsers.Count
Case 0
Return 0
Case 1
With CType(MatchedUsers(0), DotNetNuke.Entities.Users.UserInfo)
tbAddress.Text = CType(IIf(String.IsNullOrEmpty(.Profile.Unit), "", .Profile.Unit & " "), String) & .Profile.Street
tbCity.Text = .Profile.City
tbState.Text = .Profile.Region
tbZipPlus4.Text = .Profile.PostalCode
tbEmail.Text = .Email
End With
Return 1
Case Else
ddlName.Items.Clear()
ddlName.Items.Add(New ListItem(Localize("Multiple_SubjectNames_Found"), "-1"))
For Each DNNUser In MatchedUsers
ddlName.Items.Add(New ListItem(DNNUser.DisplayName, DNNUser.UserID.ToString))
Next
ddlName.Items.Add(New ListItem(Localize("None_Of_Above"), "-2"))
tdNameField.Visible = False
tdNameSelect.Visible = True
Return MatchedUsers.Count
End Select
End If
End If
End Function
Protected Sub ddlName_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlName.SelectedIndexChanged
If ddlName.SelectedIndex <> -1 Then
Select Case ddlName.SelectedValue
Case "-1" 'No Selection was made
Exit Sub
Case "-2" 'None of those found were correct - let them enter info manually
tdNameSelect.Visible = False
tdNameField.Visible = True
Case Else 'Selection has been made - get UserInfo and populate contact
Dim uc As New DotNetNuke.Entities.Users.UserController
Dim UserID As Integer = Integer.Parse(ddlName.SelectedValue)
Dim DNNUser As DotNetNuke.Entities.Users.UserInfo = uc.GetUser(PortalId, UserID)
If Not DNNUser Is Nothing Then
With DNNUser
tbName.Text = .DisplayName
tbAddress.Text = CType(IIf(String.IsNullOrEmpty(.Profile.Unit), "", .Profile.Unit & " "), String) & .Profile.Street
tbCity.Text = .Profile.City
tbState.Text = .Profile.Region
tbZipPlus4.Text = .Profile.PostalCode
tbEmail.Text = .Email
End With
tdNameSelect.Visible = False
tdNameField.Visible = True
End If
End Select
End If
End Sub
The second example is a small section of code used to do tag replacement in an e-mail template. Unlike the core's GetSystemMessage method (unless it was fixed in 4.4.0??), this will handle custom profile properties:
'just one clause in a long Select statement:
Case "User"
If propName = "VerificationCode" Then
Value = _PortalId.ToString & "-" & _UserID.ToString
ElseIf propName.StartsWith("Profile.") Then
Value = GetUserProfileProperty(_UserInfo, propName, fmtString)
Else
Value = Utilities.GetPropertyText(_UserInfo, propName, fmtString)
End If
'GetUserProfileProperty method:
Public Function GetUserProfileProperty(ByVal obj As UserInfo, ByVal propName As String, ByVal FormatString As String) As String
Dim profile As DotNetNuke.Entities.Users.UserProfile = obj.Profile
Dim Value As String = String.Empty
If propName = "Fullname" Then
Value = profile.FullName
Else
Dim prop As DotNetNuke.Entities.Profile.ProfilePropertyDefinition = profile.ProfileProperties.GetByName(propName)
If Not prop Is Nothing Then
Value = prop.PropertyValue
End If
End If
If Not String.IsNullOrEmpty(FormatString) Then Value = String.Format(FormatString, Value)
Return Value
End Function
It is my understanding that an enhanced tag replacement capability will soon be forthcoming as a core function.
Hope this helps!