0 out of 1 rated this helpful - Rate this topic

SPListItem.Update Method

Updates the database with changes that are made to the list item.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
[ClientCallableExceptionConstraintAttribute(FixedId = "thresholdexceeded", ErrorCode = , Condition = "Throttling limit is exceeded by the operation.", 
	ErrorType = typeof(SPQueryThrottledException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "4", ErrorCode = , Condition = "ParseAndSetFieldValue or SetFieldValue tried to update a readonly field. ", 
	ErrorType = typeof(SPException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "9", Condition = "Operation is not supported.", 
	ErrorType = typeof(InvalidOperationException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "2", Condition = "User does not have permissions to update this list item.", 
	ErrorType = typeof(UnauthorizedAccessException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "3", Condition = "Item does not exist. It may have been deleted by another user.", 
	ErrorType = typeof(ArgumentException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "8", Condition = "Field and list validation have failed.", 
	ErrorCode = , ErrorType = typeof(SPListDataValidationException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "saveconflict", ErrorCode = , Condition = "Save Conflict. Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes.", 
	ErrorType = typeof(SPException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "1", ErrorCode = , Condition = "Expanded recurrence items cannot be updated.To add an item to a document library, use SPFileCollection.Add().The workflow's parent item associated with this task is currently in the recycle bin, which prevents the task from being completed.", 
	ErrorType = typeof(SPException))]
[ClientCallableMethodAttribute(ReturnThisObjectState = true, CheckObjectVersion = true)]
[ClientCallableExceptionConstraintAttribute(FixedId = "5", Condition = "A duplicate value was found.", 
	ErrorCode = , ErrorType = typeof(SPDuplicateValuesFoundException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "6", Condition = "List validation has failed.", 
	ErrorCode = , ErrorType = typeof(SPListDataValidationException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "7", Condition = "Field validation has failed.", 
	ErrorCode = , ErrorType = typeof(SPListDataValidationException))]
public override void Update()
Exception Condition
SPException

The list item has been modified since it was created.

-or-

The data that was supplied for updating an item is invalid.

Note Note

When a document is checked out from a document library, its metadata cannot be modified by using the Update method.

For information about specific data formats that are used for list items in SharePoint Foundation, see the SPListItem class.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Update task not working
I using asp.net gridview in sharepoint 2010 webpart and server object model API to upgrade tasks item and nothing happen.
It works fine to show or get the all tasks list items, but not with Update ?
Not working at all
I spent hours on trying to make this to work on a custom Workflow Task content type,. it keeps on giving me the error message : "The workflow's parent item associated with this task is currently in the recycle bin, which prevents the task from being completed".

This is really annoying and I can't get why this is happening (of course I ckecked the Recycle bin, and it is alwasy empty...)
SPListItem.Update vs SystemUpdate
Some important notes on using Update vs SystemUpdate.
For Update:  Once you update, the modified by and modified dates change to when the code execute and may show the item as being last modified by "System Account".  The code also works with the item like it has nothing at all to do with the previous version.  User updates, then Code updates.

For SystemUpdate(Optional Boolean value)
If you are stuck trying to update a field for a document library, please be aware of two things in Sharepoint 2007/WSS 3.0.
1. Even if you are NOT using Checked out/checked in, the document still has a SPCheckOutStatus.ShortTerm attached to it for a brief period of time.  Trying to SPListItem.Update or SPFile.Item.Update at this point will likely tell you that the file is locked for editing.  There is a .checkoutexpires property to check if you absolutely must wait for the item to be checked back in.  (e.g. Are they really done with that darn thing?)
2. Even if you do NOT have versioning turned on, you are, in fact, working with a new version of the document.  Use SPListItem.SystemUpdate(false) in order to bypass a short term locked document.  

Full Example:
file.Item["Status"] = "Pending";
file.Item.Web.AllowUnsafeUpdates = true;
file.Item.Update() //fails miserably on ItemChanged due to the SPCheckOutStatus.ShortTerm lock.
file.Item.SystemUpdate(false); //This works while the user still has the document open.  
file.Item.Web.AllowUnsafeUpdates = false;

Hopefully this will help someone who ended up just as confused as I was when working with a DocumentLibrary event receiver for the first time.