5

I am an admin of a new site collection in a SharePoint Online environment, and I can see all the users in user pickers.

However, if i want to get the users in CSOM, i.e: var users = context.Web.SiteUsers; (where Web is the site collection), it will return only 5 or 6 users, whereas there are really more than 2000 users.

If I create a new element in any list, and selected/resolved a user in the user picker, he will be added to the SiteUsers => I can get the user in CSOM.

On the other hand, I can get all users from the root site www.{mydomain}.sharepoint.com using CSOM.

Any ideas? is there a special permission/configuration that I have to ask for?

Thanks

6

Every site collection has its own user database. It's basically just a list at ~sitecollection/_catalogs/users. The Web.SiteUsers collection will only return users who have actually visited the site collection at least once. It's also possible to programmatically add users using the Web.EnsureUser method.

To find all users in your Office 365 Tenant you need to query them through the Graph API. With REST it's possible with this query:

https://graph.windows.net/<tenantid>/users?api-version=1.6

where <tenantid> is the GUID of your tenant.

4

In People Picker, All users are coming from AD whichever selected during User Profile Synchronization Connection.

In CSOM code, "var users = context.Web.SiteUsers;" User are coming which are added in User Information List.

If you want user then you will need to add user into that list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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