Updating a list item without changing the Modified field

July 14th, 2007 by Dor

In WSS 3.0, it is now possible to update a list item (SPListItem) without changing the contents of the Modified or Editor fields.
This wonderful method is called SPListItem.SystemUpdate (has two overloads).

This solves the annoying problem where people would see some system user account that is responsible for the last update, and the time was also some strange time in which the system account did its actions.

So here’s the code sample:

SPSite site = new SPSite(“http://server/sites/someSite”);
SPWeb web = site.OpenWeb();
SPList list = web.Lists[“ListNameHere”];

// Create new item
SPListItem item = list.Items.Add();
item[“Title”] = “New Item Title”;
item[“Modified”] = new DateTime(2000, 1, 1);
item[“Created”] = new DateTime(2000, 1, 1);
item[“Author”] = web.Users.GetByEmail(“author@mydomain.com”);
item.SystemUpdate();

// Update an item
// (Using some item ID from a pre-populated list)
SPListItem itemu = list.Items.GetItemById(2);
itemu[“Title”] = “An updated item title”;
itemu[“Author”] = web.Users.GetByEmail(“author@mydomain.com”);
itemu.SystemUpdate();

Posted in English Posts, WSSv3 | del.icio.us:Updating a list item without changing the Modified field digg:Updating a list item without changing the Modified field reddit:Updating a list item without changing the Modified field

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.