• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 326
  • Last Modified:

how to get user email and profile values for non logged in users from the user ID

hello,

I have a dropdown list on a page that has a list of users for an administrator where the bound data column is the user id.  I am using the built in asp.net membership provider.

I want the administrator to be able to select a user and send them an email, which would be retrieved using the user id supplied.  I need to have the userid as the bound column for other functions on the page.  

So my question is, how do I get user information about non logged in users based on the supplied userid?

I have used the following to get a collection of all users:
   
Dim muc As MembershipUserCollection
        muc = Membership.GetAllUsers()
        Dim mu As MembershipUser
        For Each mu In muc
            chrUsername = mu.UserName
            Dim userProfile As ProfileCommon = ProfileCommon.Create(chrUsername, True)
           ''get user info here
        Next

Open in new window


but i just want to get info about one user, is there a way to do that, or do i have to loop through the entire user collection to find the one i want?
0
jordanking
Asked:
jordanking
  • 3
  • 2
1 Solution
 
Kumaraswamy RCommented:
Dim allUsers As UserInfoCollection = Membership.GetAllUsers
Dim filteredUsers As UserInfoCollection = New UserInfoCollection


If (UserRoles.SelectedIndex > 0) Then
    ' If we are filtering by role, get the users in the specified role
    Dim usersInRole() As String = Roles.GetUsersInRole(UserRoles.SelectedValue)
    ' For each user in the role, add the user details to filteredUsers
    For Each user As MembershipUser In allUsers
        For Each userInRole As String In usersInRole
            If (userInRole = user.UserName) Then
                filteredUsers.Add(user)
                Exit For
                ' Breaks out -avoid unneeded checking.
            End If
        Next
    Next
Else
   
    filteredUsers = allUsers
End If


' Bind the users to the Users GridView
DBUsers.DataSource = filteredUsers
DBUsers.DataBind


more detail;


http://www.4guysfromrolla.com/articles/052307-1.aspx
0
 
Kumaraswamy RCommented:

Dim allUsers As MembershipUserCollection= Membership.GetAllUsers
Dim filteredUsers As UserInfoCollection = New MembershipUserCollection

If (UserRoles.SelectedIndex > 0) Then
    ' If we are filtering by role, get the users in the specified role
    Dim usersInRole() As String = Roles.GetUsersInRole(UserRoles.SelectedValue)
    ' For each user in the role, add the user details to filteredUsers
    For Each user As MembershipUser In allUsers
        For Each userInRole As String In usersInRole
            If (userInRole = user.UserName) Then
                filteredUsers.Add(user)
                Exit For
                ' Breaks out -avoid unneeded checking.
            End If
        Next
    Next
Else
   
    filteredUsers = allUsers
End If


' Bind the users to the Users GridView
DBUsers.DataSource = filteredUsers
DBUsers.DataBind


more detail;


http://www.4guysfromrolla.com/articles/052307-1.aspx 

0
 
jordankingAuthor Commented:
That solution is the same as the example  I posted. I want to get the profile information of one user based on their supplied userid. I just wondered if therev was a built in way of doing this. Otherwise I will have to create a custom function which I wanted to avoid
0
 
jordankingAuthor Commented:
in the end I had to loop through all users and match the supplied id in order to isolate the individual profile information.

I did not want to do this and there must be a better way, but under the clock, I have to use it.


Dim muc As MembershipUserCollection
            muc = Membership.GetAllUsers()
            Dim mu As MembershipUser
            Dim chrUsername As String
            For Each mu In muc
                chrUsername = mu.UserName
                If mu.ProviderUserKey.ToString() = myMember.SelectedValue.ToString Then
                    chrUsername = mu.UserName
                    Dim userProfile As ProfileCommon = ProfileCommon.Create(chrUsername, True)
                    bRet = myEmail.Email_Trade_Alert(mu.Email, userProfile.FirstName + " " + userProfile.LastName, myMember.SelectedValue.ToString, dtTrade, myPlatoon.SelectedValue, myDayNight.SelectedValue, myHalf.SelectedValue, myHall.SelectedValue, 2)
                    Exit For
                End If
            Next

Open in new window

0
 
jordankingAuthor Commented:
my initial solution i posted was what i had to use.
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now