Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Accusoft 58 posts 109 karma points
    Aug 20, 2012 @ 15:56
    Accusoft
    0

    Umbraco Get Users by User Type

    If I have a list of user types (both ID and name), how can I get the users that belong to that user type (not members)? There doesn't seem to be any methods for User[] userList = User.Get ByType

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Aug 20, 2012 @ 16:44
    Tom Fulton
    1

    Hi Chris,

    How about something like this?

    var userType = UserType.GetUserType(1111);
    var users = User.getAll().Where(u => u.UserType == userType);

    -Tom

  • Accusoft 58 posts 109 karma points
    Aug 20, 2012 @ 18:11
    Accusoft
    0

    Hey Tom,

    Thanks for the reply.  Looks good but I must be missing something.  I'm getting this:

    'umbraco.BusinessLogic.User[]' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument of type 'umbraco.BusinessLogic.User[]' could be found (are you missing a using directive or an assembly reference?)

    I am including umbraco.BusinessLogic.  Any ideas?

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Aug 20, 2012 @ 18:27
    Hendy Racher
    1

    Hi Chris,

    You'll need a reference to the Linq namespace to be abe to use the Where() extension method:

    using System.Linq;

    HTH,

    Hendy

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Aug 20, 2012 @ 18:28
    Tom Fulton
    0

    Strange, what version of Umbraco are you using?  Just tested the following code and seems to be working fine:

        var userType = UserType.GetUserType(2);
        var users = umbraco.BusinessLogic.User.getAll().Where(u => u.UserType == userType);
        foreach (var user in users)
        {
                <p>@user.Name</p>
         }

    -Tom

  • Accusoft 58 posts 109 karma points
    Aug 20, 2012 @ 18:30
    Accusoft
    0

    Umbraco 4.8, but it's a custom control, not using Razor.  Thanks a bunch, can't believe I missed that!

Please Sign in or register to post replies

Write your reply to:

Draft