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 get all users in a rol?how to get all users in a rol?
Previous
 
Next
New Post
11/21/2008 7:56 AM
 

I need to get all the users in a custom rol I created.


Is there any function to get the users in a rol for a portal?

 

Thanks in advance.

 
New Post
11/21/2008 9:00 AM
Accepted Answer 

The following should work:

Dim roleName As String = "Moderators"
Dim roleCtlr As New Security.Roles.RoleController
Dim objUserRoles As ArrayList = roleCtlr.GetUserRolesByRoleName(PortalId, roleName)

The object returned by the GetUserRolesByRoleName method is an arraylist of DotNetNuke.Entities.Users.UserRoleInfo objects which include UserId, Fullname, etc. as their members.


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
11/21/2008 7:40 PM
 

Thank you William,

Your reply also answeres a question but I need to take this a step further. I need to be able to get a list of all the users in "Role A" as you described above. Then I need to be able to add all of thos users to "Role B" for a period of 7 days from the current day. Lastly I need to send each of thos users a email using the email address on their profile.

Something like:

Dim objRoles As New RoleController()


Dim UserName1 As String = Coach.Text


Dim user As UserInfo = UserController.GetUserByName(Me.PortalId, UserName1)


Dim userId As Integer = user.UserID


Dim objRoleController As DotNetNuke.Security.Roles.RoleController


objRoleController = New DotNetNuke.Security.Roles.RoleController


Dim objRoleInfo As RoleInfo = objRoles.GetRoleByName(PortalSettings.PortalId, CoachRoleName)


objRoleController.AddUserRole(Me.PortalId, userId, objRoleInfo.RoleID, Null.NullDate, Null.NullDate)



'Send email notifying video's available


Dim userEmail1 As String = UserController.GetUserByName(Me.PortalId, UserName1).Email


Dim message As New MailMessage()


Dim client As New SmtpClient


Dim commentDate As String = format(Now(), "R")


Dim textBody As String = "E-Mail Text"


Dim textView As AlternateView = AlternateView.CreateAlternateViewFromString(textBody, Nothing, "text/plain")


Try


Dim FromEmail As String = "site@****.com"


Dim ToEmail As String = userEmail1


message.AlternateViews.Add(textView)


message.Subject = "Subject"


message.From = New MailAddress(FromEmail)


message.To.Add(ToEmail)


client.Send(message)

 
New Post
11/21/2008 8:34 PM
 

You've sort of got the right idea - here are a couple of corrections/suggestions:

1. For adding the user to role CoachRoleName:

Dim objRoleController As New Security.Roles.RoleController
Dim objRoleInfo As Security.Roles.RoleInfo = objRoleController.GetRoleByName(PortalId, CoachRoleName)
Dim effectiveDate As DateTime = DateTime.Now
objRoleController.AddUserRole(PortalId, user.UserId, objRoleInfo.RoleID, effectiveDate, effectiveDate.AddDays(7.0#))

2. If the user that is being added to the role is currently logged in you may find that you have problems with the addition of the role taking effect immediately due to the cacheing of user roles. If that is the case, a call to DataCache.ClearUserCache (PortalId As Integer, user.Username) will be necessary following the addition of the user to the role.

3. Do NOT use the SmtpClient and MailMessage classes for sending emails in DNN. Instead use one of the overloads of the method SendMail from the DotNetNuke.Services.Mail.Mail class. If you leave the values for parameters SMTPxxx as an empty string, the appropriate values will be pulled from the site's SMTP settings.


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
11/24/2008 11:09 AM
 

Thank you William.

I got the code for adding the user to the role working fine. I am still needing to take that a step further.

I have it set where I can select a user that is a member of "RoleA" Then select a new role for that user to be a part of "RoleB".

What I need to do is get a list of all of the other users that are a member of "RoleA", and add all of them to "RoleB". How do I use the code above for adding the user to the role, and apply the arraylist of users in the original role so that it addes all of them to the new role?

Can you also elaberate on the use of DotNetNuke.Services.Mail for sending email and how I can get the users email dynamically

Thanks again!

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0how to get all users in a rol?how to get all users in a rol?


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