Welcome to Office Zealot Sign in | Join | Help

SPWeb: Difference between AllUsers and Users Property

Quick Quiz: Recently, I wrote a very simple web part that returns a list of users who have access to the current SharePoint site.  The code snippets below show two approaches I tried.  Do you know the difference in the results?

Method 1:

SPWeb currentSite = SPContext.Current.Web;

SPUserCollection userlist = currentSite.AllUsers;

foreach (SPUser user in userlist)

{

       ...             

}

 

Method 2:

SPWeb currentSite = SPContext.Current.Web;

SPUserCollection userlist = currentSite.Users;

foreach (SPUser user in userlist)

{

       ...             

}

 

 

SPWeb.AllUsers returns “the collection of user objects that represents all users who are either members of the site or who have browsed to the site as authenticated members of a domain group in the site

 

SPWeb.Users returns “the collection of user objects that are explicitly assigned permissions in the Web site”

 

Big difference!... the easiest way to know which is being used is to remove permissions for an existing user (who has visited the site).  He/She will continue to be appear when AllUsers is used; gone if Users is used.

 

Published Monday, May 17, 2010 12:58 AM by Mauro
Filed under: , ,

Comments

# Twitter Trackbacks for Mauro Cardarelli : SPWeb: Difference between AllUsers and Users Property [officezealot.com] on Topsy.com

Anonymous comments are disabled