SPListItem.SystemUpdate Method
Updates the database with changes that are made to the list item without changing the Modified or Modified By fields.
| Name | Description | |
|---|---|---|
|
SystemUpdate() | Updates the database with changes made to the list item without changing the Modified or Modified By fields. |
|
SystemUpdate(Boolean) | Updates the database with changes that are made to the list item without changing the Modified or Modified By fields, or optionally, the item version. |
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.
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.
- 6/3/2010
- Jack Burnish