Query users

This topic contains examples of how to:

  • Query a single user
  • Query all users
  • Query user by first name

Querying a single user

To query a specific user, you must perform the following:

  1. Get instance of the user manager.
    The manager is represented by the UserManager class. For more information about getting the instance, see For developers: Users.
  2. Get the user.
    To get the specified user, call the GetUser method of the UserManager class. It has two overloads:
    • GetUser(string username) – returns the user with the specified username.
    • GetUser(Guid id) – returns the user with the specified ID.

NOTE: To learn how to query the profile of the user, read For developers: Query user profiles.

Here is a code example:

Querying all users

To query all users, you must perform the following:

  1. Get instance of the user manager.
    The manager is represented by the UserManager class. For more information about getting the instance, see For developers: Users.
  2. Get all users.
    To get all users, call the GetUsers method of the UserManager class.

Here is a code example:

Querying a user by first name

Normally you can get the user object by any of the User class properties. For example in order to get a user by username, you can use the following code:

However some of the fields of the user are no longer properties of the User class like first name and last name. Instead you should use the SitefinityProfile. Here is a sample code that demonstrates how to query all users by first name:




Was this article helpful?

Next article

Modify users