There are 2 ways by which the SpListItem data can be updated.
The below snippet is usually used to update SPListItems.
SpListItem.Update() :
The Item.Update() updates the database with the changes, creates a new version and changes the Modified and Modified By fields.
SPList list = web.Lists["myList"];
SPListItem item = list.Items[0]; // First item in the list
item["myField"] = “Test update”;
item.Update();
list.Update();
SpListItem.SystemUpdate() :
If you want to avoid version changes, Modified and Modified By fields from getting updated , Item.SystemUpdate() would be the right way to do it.
SPList list = web.Lists["myList"];
SPListItem item = list.Items[0];
item["myField"] = “Test update”;
item.SystemUpdate(false);
list.Update();
The argument false informs the SP object Model not increment versions.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment