SPEventReceiverType.CheckingIn

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!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: