0

I have "User Information List" and i want to get user of current site collection only but it is fetching all users of Farm.

Below is the code.

SPSite currentSite = SPContext.Current.Site; SPWeb web =currentSite.OpenWeb();
SPUserCollection userCollection = web.SiteUsers;
SPList userList = web.Lists.TryGetList("User Information List"); 
if  (userList != null)
{
     foreach (SPListItem item in userList.Items)
     {
     }
}

Not sure what i am doing wrong! Any thoughts on this?

2 Answers 2

0

Using SPWeb.AllUsers should give you all users who have direct permissions on the site, or who have logged in at least once (thanks to permissions given through a group membership).

0

Your code is doing two things. You're 1) populating userCollection with web.SiteUsers and separately you're 2) setting userList equal to the user information list. Your foreach loop is only looking at userList instead of looking at userCollection, which should contain all of that site collection's users (both in and not in groups)

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.