SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to set the current user in a field that is User Lookup. I have the following code which works fine for the datetime field but not for the user. It does not return any error, but when I try to edit the document properties again the user was not saved.

public override void ItemUpdating(SPItemEventProperties properties)
           Logger.LogDebug("IncomingDocumentListEvents", "ItemUpdating(SPItemEventProperties properties)", "BEGIN");
           string contentTypeName = properties.ListItem.ContentType.Name;
           if (contentTypeName == Subsidies.Common.Constants.CONTENTTYPES_BANKCERTIFICATE_NAME)
                   base.EventFiringEnabled = false;
                   SPItemEventDataCollection afterProperties = properties.AfterProperties;
                   SPListItem item = properties.ListItem;
                    if (item != null)
                       string listName = item.ParentList.RootFolder.Name;
                       string approvedStatus = item.GetTaxonomyFieldValueByLanguage(item.Web.Site, Subsidies.Common.Constants.FIELDS_INCOMINGODOCUMENTSTATUS_NAME, 1043);

                       if (approvedStatus == Subsidies.Common.Constants.FIELDS_INCOMINGODOCUMENTAPPROVEDSTATUS_NAME)
                           SPUser user = item.Web.SiteUsers[item.Web.CurrentUser.LoginName];
                           afterProperties[Subsidies.Common.Constants.FIELDS_ACCOUNTINGAUDITORNAME_NAME] = user;
                           afterProperties.SetAfterPropertyValue(Subsidies.Common.Constants.FIELDS_APPROVALDATE_NAME, DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ")); 

               catch (Exception ex)
                   Logger.LogError("IncomingDocumentListEvents", "ItemUpdating(SPItemEventProperties properties)", ex);
                   properties.ErrorMessage = "";
                   properties.Cancel = true;
                   base.EventFiringEnabled = true;

           Logger.LogDebug("AgendaPointsProposedEvents", "ItemUpdated(SPItemEventProperties properties)", "END");
share|improve this question
The ItemUpdating is used for validation. If you want to set the values of fields, do it in the ItemUpdated event instead. – Ravi Suthar Aug 16 '12 at 12:48
indeed it works in the itemupdated – Esteban V Aug 16 '12 at 13:09
just put it as an answer to give you the points – Esteban V Aug 16 '12 at 13:22
up vote 1 down vote accepted

The ItemUpdating is used for validation. If you want to set the values of fields, do it in the ItemUpdated event instead...

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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