Any pointers to Which API will update versioning in SharePoint 2013? And any code snippet to do it?
I have checked update() vs systemupdate() but not sure about the API part.
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityAny pointers to Which API will update versioning in SharePoint 2013? And any code snippet to do it?
I have checked update() vs systemupdate() but not sure about the API part.
For a SharePoint list, the SystemUpdate method is used if updating modified fields (Modified, Modified By) and adding new version are not required. The Update method updates both the modified fields and version.
Moreover, these APIs exist in both client and server side object models. The server side SystemUpdate has one overload "boolean" which if true increments the item version but does not update the modified fields.
Client side (CSOM) sample
ClientContext context = new ClientContext(site_url);
Web web = context.Web;
List list = web.Lists.GetByTitle(list_name);
ListItem oListItem = list.GetItemById(1);
oListItem["Title"] = "My New Item!";
//to ignore updating modified fields and version
//oListItem.SystemUpdate();
//to update modified fields and version
//oListItem.Update();
context.ExecuteQuery();
Server side sample
using(SPSite site = new SPSite(site_url))
{
using(SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["list_name"];
SPListItem item = list.GetItemById(1);
item["Title"] = "My New Item!";
//to ignore updating modified fields and version
//item.SystemUpdate();
//to ignore updating modified fields but update version
//item.SystemUpdate(true);
//to update modified fields and version
//item.Update();
}
}