Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0How to Retrieve User Profile PropertiesHow to Retrieve User Profile Properties
Previous
 
Next
New Post
2/1/2007 12:16 PM
 

I wonder if anyone could point me to some code where it shows how to retrieve profile details for a logged in user  from within a custom module

For instance, if I need to retrieve the address and phone number for a particular user, and if found, then do some more tasks...

Thanks for any direction.

 
New Post
2/1/2007 1:43 PM
 

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!


Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
New Post
2/1/2007 2:24 PM
 

Bill, 

Thank you very much for your response and code snippet. I only have taken a quick glance so far but I already see that I am lacking in the area you first mention; that is, how do I retrieve or create a UserInfo object for either the currently logged in user or another user? I think I have to get it from the cache somehow, right?

Could you please help me with this (provide a code snippet) and I apologize for the degree of green-ness of my newbie question.

Frank

 
New Post
2/1/2007 3:33 PM
 

Ok, I found one way - declare a userObject like so:

private UserInfo userInfo = UserController.GetCurrentUserInfo();

and I should be able to retrieve properties like so:

int id = userInfo.UserID;

Is there a better way?

 

 
New Post
2/1/2007 4:48 PM
 

Do you know the truth when you hear it?
Néstor Sánchez
The Dúnadan Raptor -->Follow Me on Twitter Now!
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0How to Retrieve User Profile PropertiesHow to Retrieve User Profile Properties


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out