Represents a user in Microsoft SharePoint Foundation.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
Use the AllUsers property of the SPWeb class to return all the users of a site. This includes users granted permissions directly, users granted permissions through a group who have then visited the site, and users who have been referenced in a person field, such as being assigned a task. Calling AllUsers[name] will throw an exception if the user is not there.
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")
For general information about users and security, see Security, Users, and Groups in Windows SharePoint Services.
The following code example modifies the e-mail address, display name, and notes for a specified user object.
Dim siteCollection As SPSite = SPControl.GetContextSite(Context) Dim site As SPWeb = siteCollection.AllWebs("Site_Name") Dim user As SPUser = site.AllUsers("User_Name") user.Email = "E-mail_Address" user.Name = "Display_Name" user.Notes = "User_Notes" user.Update()
Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.