1

I have written an itemupdated event receiver for a SPList in my SP 2013 / VS 2013 solution [ on-premises] . Now I want to trigger this itemupdated event when the item is created in the SPList .But when i added an item in the splist its not triggering this itemupdated event

i have noticed that , itemupdated event and itemcheckedin event triggered for a documentlibrary[ version enabled]. but for a splist whose versioning is NOT enabled , this itemupdated event handler is not working.

How can i trigger an itemupdated eventhandler for a splistitem when an item is added into the splist ?

public class NPDListEvntRcvr : SPItemEventReceiver
{
    /// <summary>
    /// An item was added.
    /// </summary>
    public override void ItemAdded(SPItemEventProperties properties)
    {
       // base.ItemAdded(properties);
    }

    /// <summary>
    /// An item was updated.
    /// </summary>
    public override void ItemUpdated(SPItemEventProperties properties)
    {
        //base.ItemUpdated(properties);


        SPUser currUser = properties.Web.CurrentUser;

        this.EventFiringEnabled = false;

        try
        {

            // if (properties.ListTitle.ToLower() == NPDListNames.ITEMLEVELPERMISSIONSLIST.ToString())
            // {

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {

                SPSite CurrentSite = new SPSite(properties.SiteId);
                SPWeb CurrentWeb = CurrentSite.OpenWeb(properties.RelativeWebUrl);

                SPList CurrentList = CurrentWeb.Lists[properties.ListId];

                SPListItem CurrentListItem;
                CurrentListItem = CurrentWeb.Lists[properties.ListId].GetItemById(properties.ListItem.ID);
                // = IsDocumentLibrary(CurrentListItem);
             //   blnIsSPList = IsSPList(CurrentListItem);
             //   blnIsFolderinDocLib = IsFolderDocumenttLibrary(CurrentListItem);

               // string authorFieldValue = CurrentListItem["Author"].ToString();
                SPFieldUserValue userValue = new SPFieldUserValue(CurrentWeb, CurrentListItem[SPBuiltInFieldId.Author].ToString());
                SPUser author = userValue.User;


                if (!CurrentListItem.HasUniqueRoleAssignments)
                {
                    CurrentListItem.BreakRoleInheritance(true);
                    CurrentWeb.AllowUnsafeUpdates = true;
  • Use the itemadded event – Gautam Sheth Jan 27 '17 at 10:01
  • what will happen if i update an item in the list by using the Edit-->Edit properties. am not able to trigger the / apply the itempermissions in the itemadded eventhandler , since i added the code in the itemupdated eventhandler method. but this holds true for a document library item.it fires both itemadded and itemupdated in the case of doc .lib – SaMolPP Jan 27 '17 at 10:02
  • it will trigger the itemupdated event. – Gautam Sheth Jan 27 '17 at 10:03
  • in SPList , can i trigger the itemupdatedevethandler using the itemadded event? is this by design ? as suggested by you, i need to duplicate the code , thats wrtten in the itemupdated eventhandler. wont it be a bad practice? – SaMolPP Jan 27 '17 at 10:05
  • No, when you click on add new item and save it, it will trigger itemadded event. So do you want the same process to trigger for itemadded and itemupdated ? – Gautam Sheth Jan 27 '17 at 10:07

Your Answer

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

Browse other questions tagged or ask your own question.