3

In my provider-hosted app I load the UserCollection from SharePoint by CSOM (Client Side Object Model), like this:

UserCollection users = web.SiteUsers;
clientContext.Load<UserCollection>(users);
clientContext.ExecuteQuery();

But I only want "normal" users to be displayed in my app. The result given here also shows users which seem to be system users, like:

  • _SPOCacheFull
  • System Account
  • Everyone
  • Everyone except external users

How can I determine if a user is a normal site user or a system user?

I checked the groups but most of the system users don't have any groups. Also the email is mostly empty but not always.

1 Answer 1

2

The following User properties could be used for that purpose:

The below example demonstrates how to determine a "regular" users in Web.SiteUsers:

public static IEnumerable<User> LoadUsers(ClientContext context)
{
   var users = context.LoadQuery(context.Web.SiteUsers.Where(u => u.PrincipalType == PrincipalType.User && u.UserId.NameIdIssuer == "urn:federation:microsoftonline"));
   context.ExecuteQuery();
   return users;
}
1
  • 1
    Ah very nice! The urn:federation:microsoftonline Value is indeed very helpful as most of the SharePoint System users have PrincipalType.User aswell.
    – Vinz
    Commented Sep 11, 2014 at 7:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.