我正在使用sharepoint服务器2013并使用VS2013。
我的任务是在自定义列表上创建一个事件接收器,我在其上使用了事件ItemAdded。
每件事情都运作良好:
转到列表>>创建一个新项目>>事件接收器是直接启动的。
然后我为我的列表创建一个自定义表单(使用webpart),但事件Receiver没有激发! (此WebPart是一个自定义表单,其中包含与列表相同的字段,当我提交新请求时,新项目已创建到列表中)
最后我注意到,当项目添加到列表中时,事件接收器正在工作,当我从外部添加新项目时,该事件接收器无法正常工作!
请注意,之前我使用过这个场景并且它已经完成了。
我的活动接收者代码:
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>
有人可以帮忙吗