Use the AllUsers or SiteUsers property of the SPWeb class, the GetAllAuthenticatedUsers method of the SPUtility class, or the GetUniqueUsers method of the SPAlertCollection class, to return the following:
-
All the users of a site
-
All the users in the site collection
-
All authenticated users of a site
-
A list of users for a collection of alerts.
Otherwise, use the Users property of the SPGroup, SPRole, or SPWeb class to return the users in a group, role definition, or site.
Use an indexer to return a single user from the collection. For example, if the collection is assigned to a variable named collUsers, use collUsers[index] in C#, or collUsers(index) in Visual Basic, where index is either the index number of the user in the collection or the user name of the user.
Every user has a unique member ID (ID property), has the permissions associated with that membership, and can be represented by an SPMember object. The following example assigns a user to an SPMember object, given a specified SharePoint Web site:
Dim oWebsite As SPWeb = SPContext.Current.Web
Dim oMember As SPMember = oWebsite.AllUsers("Domain\\User_Alias")
SPWeb oWebsite = SPContext.Current.Web;
SPMember oMember = oWebsite.AllUsers["Domain\\User_Alias"];
For general information about users and security, see Security, Users, and Groups.