2

Am trying to perform a basic insert to custom list item when an item added from sub-site source list but the insert command don't execute. Any idea?

Elememnts.xml setting to hook the receiver:

<?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <Receivers ListUrl="Support/Lists/Suggestions" Scope="Web">
         <Receiver>
         <Name>EventRcvr_MPW_SuggestionItemAdding</Name>
         <Type>ItemAdding</Type>
         <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
         <Class>PortalV2.EventRcvr_MPW_Suggestion.EventRcvr_MPW_Suggestion</Class>
         <SequenceNumber>10000</SequenceNumber>
  </Receiver>

Insert code:

 public override void ItemAdded(SPItemEventProperties properties)
 {
      base.ItemAdded(properties);
      this.EventFiringEnabled = false; //prevent multiple insert

            using (SPWeb web = properties.OpenWeb())
            {
                    SPList list = web.Lists["MyPortalWinner"];
                    web.AllowUnsafeUpdates = true;
                    SPListItem item = list.Items.Add();
                    item["Title"] = "SUGGESTION";
                    item.Update();
                    web.AllowUnsafeUpdates = false;


            }

           this.EventFiringEnabled = true; //reset
    }
7
  • Please clarify if your event receiver function itself is not called or the code inside event receiver doesn't work as expected.
    – Prakash
    Nov 28, 2015 at 10:58
  • @Prakash-CrowCanyon Came to know using SP Manager 2013, the event receiver was not bind to the source list. Most definitely the same reason why ItemAdding() not firing. What am I missing to bind event properly?
    – Jonathan.B
    Nov 28, 2015 at 11:28
  • Check if your feature is activated on site and that the feature contains the event receiver.
    – Prakash
    Nov 28, 2015 at 11:38
  • @Prakash-CrowCanyon - bit lost here. Appreciate if you can guide me.
    – Jonathan.B
    Nov 28, 2015 at 13:34
  • 1
    SPItemEventProperties has a Site property, please try using it: msdn.microsoft.com/en-us/library/… Also, do not dispose this object.
    – Prakash
    Nov 30, 2015 at 7:25

2 Answers 2

1

you have to play something on ListUrl="Support/Lists/Suggestions", try for ListUrl="Suggestions"

0

Here's how it was fixed.

public override void ItemAdded(SPItemEventProperties properties)
{
  base.ItemAdded(properties);
  this.EventFiringEnabled = false; //prevent multiple insert

        using (SPWeb web = properties.OpenWeb())
        {
                SPList list = web.Lists["MyList"];
                web.AllowUnsafeUpdates = true;
                SPListItem item = list.Items.Add();
                item["Title"] = "SUGGESTION";
                item.Update();
                web.AllowUnsafeUpdates = false;

        }

       this.EventFiringEnabled = true; //reset
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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