I was just working with document libraries and the dreaded “CheckingIn”-Event (SPEventReceiverType.CheckingIn).
The problem you get, when you try to change the
properties.ListItem (SPItemEventProperties.SPListItem) is that when listItem.Update(); (listItem.Update(bool);) are executed an Exception “Save conflict” occurs and your listitem is not checked in at all.
There are two nice blogs with good hints to the problem (also read the comments):
For me, it is not acceptable to catch exceptions and try the same action again, so I tried the variant of
listItem.SystemUpdate(false);
This of course requires elevation of privileges, because system update is supposed to be done by the system user, so the complete code looks like this:
public override void ItemCheckingIn(SPItemEventProperties properties)
{
SPSecurity.RunWithElevatedPrivileges (
delegate
{
SPListItem listItem = properties.Listitem;
// change your listItem here
// listItem["MyTextFieldInternalName"] = "foo bar";
listItem.SystemUpdate(false);
});
}
This worked for me. I hope it does for you, too!