I'm trying to list the members by the member group but I can't see a method to get a member by either group or type. The code below is working but it does a recursive loop over every member for every group in the installation which is not good.
Does anyone know of a better way to do this?
MemberGroup[] memberGroups = MemberGroup.GetAll;
foreach(var memberGroup in memberGroups)
{
Response.Write("<b>" + memberGroup.Text + "</b><br />");
Member[] members = Member.GetAll;
foreach (var member in members)
{
if(member.Groups.ContainsKey(memberGroup.Id))
{
Response.Write(member.LoginName + "<br />");
}
}
}
Ignore the response write, this is just for debugging.
I've never messed with Members in Umbraco but 'obsolete' in general means that, although such functionality is still available, it is only for backwards compatibility purposes, should be considered deprecated and should not be used; this is almost always because a newer, more desirable way of doing the thing has been introduced (big but here though: it should still do what is always did and that should not change!).
So, I'm doing this a lot here these days, but to guess, you might consider doing what it says and using 'Role.GetUser'; however since you use a couple of methods there I'm not 100% sure which of those is actually deprecated, so let's just replace it and see what happens (incidentally, with the code above posted by Matt):
Anotner note, community-wise, is that since this problem has been marked as 'solved' and you didn't manage to derive a fix for yourself from the proposed solution, starting a topic dedicated to your problem seems more proper.
Get members by member group
I'm trying to list the members by the member group but I can't see a method to get a member by either group or type. The code below is working but it does a recursive loop over every member for every group in the installation which is not good.
Does anyone know of a better way to do this?
Ignore the response write, this is just for debugging.
Max
You could use the roles provider?
This would get you a list of user names, so if you just pulled all members back and cross referenced, that could work?
Matt
Have a look at this post, especially reply from @slace...
Hope this helps.
Regards,
/Dirk
Hiya,
The member group class has a getmembers method, that should be what you're after:
http://umbraco.org/apiDocs/html/AllMembers_T_umbraco_cms_businesslogic_member_MemberGroup.htm
Perfect, thanks for all the answers.
I will use roles provider as this seems like the preferred method.
Hi there,
Im trying to get all the member of a specific group and I was able to get their names using the Roles.GetUsersInRole("memberGroup");
However, it seems like all I get is their names. How can I get all the other properties like address and id?
Many thanks
mkariti
Anyone know how to achieve this?
Im using this one:
But is says that this is an obsolete method --> please use the .Role.getuser
What does it means by obsolete ?
Also, can anyone post an example? as I said above I only get the name without anyother details like Id.
Cheers
mkariti
mkariti,
I've never messed with Members in Umbraco but 'obsolete' in general means that, although such functionality is still available, it is only for backwards compatibility purposes, should be considered deprecated and should not be used; this is almost always because a newer, more desirable way of doing the thing has been introduced (big but here though: it should still do what is always did and that should not change!).
So, I'm doing this a lot here these days, but to guess, you might consider doing what it says and using 'Role.GetUser'; however since you use a couple of methods there I'm not 100% sure which of those is actually deprecated, so let's just replace it and see what happens (incidentally, with the code above posted by Matt):
Anotner note, community-wise, is that since this problem has been marked as 'solved' and you didn't manage to derive a fix for yourself from the proposed solution, starting a topic dedicated to your problem seems more proper.
Hi Grant,
Many thanks for your reply.
So basically the best bet will be to use 2 methods? 1 to get the names and the second to reference to other method let say to get the ID's?
Also, duly noted regarding the solved Message.
Many thanks
mkariti
Might this work?
Or,
Great!
Cheers
is working on a reply...