Share via


SPUser.Update method

Updates the database with changes made to the properties of the user object.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaration
Public Sub Update
'Usage
Dim instance As SPUser

instance.Update()
public void Update()

Exceptions

Exception Condition
SPException

The user is a site collection administrator or site collection auditor.

-or-

The properties can only be set for an application principal.

Remarks

Call this method after setting the values for the properties of the user object to save the changes in the database.

Examples

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()
SPSite oSiteCollection = SPContext.Current.Site;
using (SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"])
{
    SPUser oUser = oWebsite.AllUsers["User_Name"];
    oUser.Email = " E-mail_Address";
    oUser.Name = " Display_Name";
    oUser.Notes = " User_Notes";
    oUser.Update();
}

Note

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.

See also

Reference

SPUser class

SPUser members

Microsoft.SharePoint namespace