1

I have a document library that upon an item being liked (updated) it adds an entry in to another list. Everything works fine except the new list item is being created by the System Account instead of the person doing the liking. All the other event handlers I have add the item as the user, but there is something odd about the like functionality running as the System Account. Any ideas how to get the user?

1

I ended up just parsing the "LikedBy" column as the last user would be the one who most recently liked the item.

var split = listItem["LikedBy"].Split(";#".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
for (var i = split.Length - 1; i >= 0; i--)
{
    int userId;
    if (int.TryParse(split[i], out userId)) return userId;
}
return 0;
0

Have you tried properties.CurrentUserId and explicity pass that to the Created property of the new listitem ?

1
  • I tried that but in the ItemUpdated event properties.CurrentUserId is 0 (System Account). This only occurs when an update is triggered by a "like" though. If I just edit the item it comes back as the logged in user. – elSpanielo Aug 22 '14 at 15:28
0

As, suggested by Shailen, get the user's Id and update the author field. Check the sequence of 'EventFiringEnabled' to make sure your code is running after SP's.

item[SPBuiltInFieldId.Author] = userId;
item.SystemUpdate(false);

Also, make sure you're wrapping your code inside

  SPSecurity.RunWithElevatedPrivileges(delegate() { 
   ...
  });
1
  • The UserId is coming back as 0 (System Account) so I cannot set that. This only happens when an update is triggered by a Like though. – elSpanielo Aug 22 '14 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.