Condividi tramite


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)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
<ClientCallableExceptionConstraintAttribute(FixedId := "8", ErrorType := GetType(SPDuplicateValuesFoundException),  _
    ErrorCode := , Condition := "Duplicate value was found.")> _
<ClientCallableExceptionConstraintAttribute(FixedId := "3", ErrorType := GetType(SPException),  _
    ErrorCode := , Condition := "Item does not exist.The page you selected contains an item that does not exist.  It may have been deleted by another user.")> _
<ClientCallableExceptionConstraintAttribute(FixedId := "4", ErrorType := GetType(UnauthorizedAccessException),  _
    Condition := "User does not have permissions to update this list item.")> _
<ClientCallableExceptionConstraintAttribute(FixedId := "5", ErrorType := GetType(SPListDataValidationException),  _
    ErrorCode := , Condition := "Validation for the current list item failed.")> _
<ClientCallableExceptionConstraintAttribute(FixedId := "6", ErrorType := GetType(SPListDataValidationException),  _
    ErrorCode := , Condition := "Validation for a field in the current list item failed.")> _
<ClientCallableExceptionConstraintAttribute(FixedId := "7", ErrorType := GetType(SPListDataValidationException),  _
    ErrorCode := , Condition := "Validation for the current list item and for one of its fields failed.")> _
<ClientCallableAttribute> _
Public Sub Update
'Usage
Dim instance As SPUser

instance.Update()
[ClientCallableExceptionConstraintAttribute(FixedId = "8", ErrorType = typeof(SPDuplicateValuesFoundException), 
    ErrorCode = , Condition = "Duplicate value was found.")]
[ClientCallableExceptionConstraintAttribute(FixedId = "3", ErrorType = typeof(SPException), 
    ErrorCode = , Condition = "Item does not exist.The page you selected contains an item that does not exist.  It may have been deleted by another user.")]
[ClientCallableExceptionConstraintAttribute(FixedId = "4", ErrorType = typeof(UnauthorizedAccessException), 
    Condition = "User does not have permissions to update this list item.")]
[ClientCallableExceptionConstraintAttribute(FixedId = "5", ErrorType = typeof(SPListDataValidationException), 
    ErrorCode = , Condition = "Validation for the current list item failed.")]
[ClientCallableExceptionConstraintAttribute(FixedId = "6", ErrorType = typeof(SPListDataValidationException), 
    ErrorCode = , Condition = "Validation for a field in the current list item failed.")]
[ClientCallableExceptionConstraintAttribute(FixedId = "7", ErrorType = typeof(SPListDataValidationException), 
    ErrorCode = , Condition = "Validation for the current list item and for one of its fields failed.")]
[ClientCallableAttribute]
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