Search code examples
sharepointsharepoint-2007

How to Create a new Version Programmatically in Sharepoint List


I have a choice field called stage lets assume it has following values used as a dropdown

stage1
stage2
stage3

on change of stage I would like to record TimeStamp and Who updated the item information

How can I do it on my List without creating any other list, I think using Versioning I can add a new version whenever before and after properties are change on that Field.

//ItemUpdating Event 
if(properties.ListItem["Stage"] != properties.AfterProperties["Stage"])
{
   //Create a Version;
}

I cannot find how to create a version here.


Solution

  • if you have versioning enabled, every time you call SPListItem.Update method, SharePoint automatically creates new version.

    If you don't want new version to be created, call UpdateOverwriteVersion.

    If you don't want to modify Modified By and Modified fields, then call SystemUpdate (see overloaded SystemUpdate, where you pass argument also not to create new version).