Monday, 26 May 2014

item.Update(); and item.SystemUpdate(false);

SPList list = web.Lists["myList"];
SPListItem item = list.Items[0];
item["myField"] = "my value";
item.Update();
list.Update();
This code works perfect for end-user scenarios. It creates automatically new version of list item as Update method is called. I needed no new versions and therefore this solution wasn't great help for me. I found list item's method SystemUpdate. The following code is same as the previous one but instead of Update it uses SystemUpdate.
SPList list = web.Lists["myList"];
SPListItem item = list.Items[0];
item["myField"] = "my value";
item.SystemUpdate(false);
list.Update();
SystemUpdate method avoids SharePoint 2007 to change modified date and modifier fields. Argument false tells that no new versions are expected. SystemUpdate solved my problem perfectly well.