Compartilhar via


SPUser Class

The SPUser class represents a user in Microsoft Windows SharePoint Services.

System.Object

   Microsoft.SharePoint.SPMember

      Microsoft.SharePoint.SPUser

Public Methods

The following table shows the public methods of the SPUser class and a brief description of each.

Name Description
ToString Returns the user name of the user.
Update Updates the database with changes made to the properties of the user object.

Public Properties

The following table shows the public properties of the SPUser class, the data type of each property, and a brief description of each.

Name Data Type Description
Alerts Microsoft.SharePoint.SPAlertCollection Gets the collection of alerts for the user.
Email String Gets or sets the e-mail address of the user.
Groups Microsoft.SharePoint.SPGroupCollection Gets the collection of cross-site groups of which the user is a member.
ID Int32 Gets the member ID for the user.
IsDomainGroup Boolean Gets a Boolean value that indicates whether the user is a domain group.
IsSiteAdmin Boolean Gets or sets a Boolean value that specifies whether the user is a site collection administrator.
LoginName String Gets the user name of the user.
Name String Gets or sets the display name of the user.
Notes String Gets or sets notes for the user.
OwnedGroups Microsoft.SharePoint.SPGroupCollection Gets the collection of cross-site groups of which the user is an owner.
ParentWeb Microsoft.SharePoint.SPWeb Gets the parent site for the user.
Roles Microsoft.SharePoint.SPRoleCollection Gets the collection of site groups of which the user is a member.
Sid String Gets the unique security ID for the network account of the user.
Xml String Gets the XML representation of the user object.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread safe.

Remarks

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 all the users of a site, all the users in the site collection, all the authenticated users of a site, or 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 cross-site group, site group, or site. Use an indexer to return a single user from the collection. For example, if the collection is assigned to a variable named myUsers, use myUsers[index] in C#, or myUsers(index) in Visual Basic .NET, 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, 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:

SPMember myMember = site.Users["User_Name"];

For general information about users and security, see Security, Users, and Groups Overview.

Example

The following code example modifies the e-mail address, display name, and notes for a specified user object.

This example requires using directives (Imports in Visual Basic) for both the Microsoft.SharePoint and Microsoft.SharePoint.WebControls namespaces.

Requirements

Namespace: Microsoft.SharePoint

Platforms: Microsoft Windows Server 2003

Assembly: Windows SharePoint Services (in Microsoft.SharePoint.dll)

Security: Code Access Security