Answered by:
Event Receiver not working into SharePoint List all times

Question
-
i'm working on a sharepoint server 2013 and using VS2013.
My task is to create an Event Receivers on a custom list, i used the event ItemAdded on it.
Every thing is working well:
Go to list >> create a new item >> the event receiver was fired up directly.Then i create a custom form (using webpart) for my list, but the event Receiver didn't fired up! ( This WebPart is a custom form that contains the same fields as the list and when i submit a new request a new item was created into the list )
Finally i noticed that the Event receiver is working when item added into the list only and not working when i add new item to list from Outside!
Note that i used this scenario before and it was worked.
My event receiver code:
using System; using System.Security.Permissions; using Microsoft.SharePoint; using Microsoft.SharePoint.Utilities; using Microsoft.SharePoint.Workflow; using ProjectName.SharePoint.Utility.Code; using ProjectName.SharePoint.EventReceiver.Code; namespace ProjectName.SharePoint.EventReceiver.TestEvtRvr { public class TestEvtRvr : SPItemEventReceiver { /// <summary> /// An item was added. /// </summary> public override void ItemAdded(SPItemEventProperties properties) { if (Helper.GetListInternalName(properties, properties.List.DefaultDisplayFormUrl).Equals(ListName.Test)) { RequestDetails requestDetails = new RequestDetails(); requestDetails.emailTemplatetListInternalName = "EmailTemplates"; requestDetails.userTemplate = "Test_USER";//User template, stored in SP list. try { if (!String.IsNullOrWhiteSpace(Convert.ToString(properties.AfterProperties[Columns.Email]))) requestDetails.email = Convert.ToString(properties.AfterProperties[Columns.Email]); DateTime saveNow = DateTime.Now; requestDetails.created = saveNow.ToString(); if (properties.ListItem.Fields.ContainsField(Columns.RequestNumber)) properties.ListItem[Columns.RequestNumber] = requestDetails.requestNumber; properties.ListItem.Update(); requestDetails.emailTokens.Add("[Email]", requestDetails.email); requestDetails.emailTokens.Add("[RequestNumber]", requestDetails.requestNumber); requestDetails.emailTokens.Add("[CreatedOn]", requestDetails.created); } catch (Exception ex) { Utilities.WriteToEventViewer(ex); } if (!String.IsNullOrEmpty(requestDetails.email)) { try { //Send Email to User if (!string.IsNullOrWhiteSpace(requestDetails.userTemplate)) { Helper.SendEmailFromTemplate(requestDetails.email, null, null, requestDetails.userTemplate, requestDetails.emailTokens, properties.OpenWeb(), requestDetails.emailTemplatetListInternalName); } else { Utilities.WriteToEventViewer("\nTest: User Template is not defined"); } } catch (Exception ex) { Utilities.WriteToEventViewer(ex); } } base.ItemAdded(properties); } } }
Element.xml:
<?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Receivers ListUrl="Lists/Test"> <Receiver> <Name>TestEvtRvrItemAdded</Name> <Type>ItemAdded</Type> <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly> <Class>ProjectName.SharePoint.EventReceiver.TestEvtRvr.TestEvtRvr</Class> <SequenceNumber>10000</SequenceNumber> </Receiver> </Receivers> </Elements>
I posted this question in multiple places and I got no answer..
how it can be possible, looking for help. Please suggest?
Thursday, February 5, 2015 7:48 AM
Answers
-
Hi,
The following troubleshooting steps for your reference:
1. Using the following code to check if it works.
using System; using System.Security.Permissions; using Microsoft.SharePoint; using Microsoft.SharePoint.Utilities; using Microsoft.SharePoint.Workflow; using ProjectName.SharePoint.Utility.Code; using ProjectName.SharePoint.EventReceiver.Code; namespace ProjectName.SharePoint.EventReceiver.TestEvtRvr { public class TestEvtRvr : SPItemEventReceiver { /// <summary> /// An item was added. ///</summary> public override void ItemAdded(SPItemEventProperties properties) { Utilities.WriteToEventViewer("\nTest: item added test."); base.ItemAdded(properties); } } }
2. If the code above works, I suggest you debug your event receiver.
3. If the code above don't works, I suggest you check your custom form web part code or provide the code.
Best Regards
Dennis Guo
TechNet Community Support- Proposed as answer by Patrick_Liang Thursday, February 12, 2015 2:39 PM
- Marked as answer by Patrick_Liang Friday, February 13, 2015 12:28 PM
Friday, February 6, 2015 8:53 AM