Monday, 26 December 2011

SpListItem.Update and SpListItem.SystemUpdate and SpListItem.UpdateOverwriteVersion

1.     Update(): With this method you can update the list item. But it will change values  in 'Modified By' to the SHAREPOINT\system account and sets the Modified column to the current date time. If versioning is enabled, the version is increased.

2.     SystemUpdate(): This method also updates the list item but it will not change the values in the Modified By and the Modified column. This method comes with two overloads. You can also specify a Boolean value to indicate if you want to increase the version number or not ( By default it will be fasle, so that the version will not be updated).

3.     UpdateOverwriteVersion(): This method updates the list item without changing the version number. 

Example:

 using (SPSite site = new SPSite("http://testsite"))
 {
        using (SPWeb web = site.OpenWeb())
        {
            SPList list = web.Lists["Test List"];
            SPListItem item = list.Items[1];
            item["Title"] = "Sample Update";
            item.Update(); // update version,modified and modified column
           //item.SystemUpdate(); // update version number
          //item. UpdateOverwriteVersion(); // update version number.
           list.Update();
         }

  }

No comments:

Post a Comment