【发布时间】:2016-08-18 18:55:42
【问题描述】:
我有一个 SharePoint 列表,我在其中注册了一个自定义 ItemUpdating 事件接收器,但我在此解决方案中看到了一些非常奇怪的行为。如果我将任何代码添加到除 base.ItemUpdating 之外的事件接收器,则会发生此行为。
如果我调试事件接收器会发生什么,我可以看到 properties.AfterProperties 具有在字段中输入的所有值,而 properties.ListItem 具有原始项目。但是一旦 ER 完成运行并且页面重新加载,什么都不会保存,它只会返回到我更改值之前的状态。更奇怪的是,如果我手动设置类似于下面的 after 属性,它可以工作并且更新被正确保存。所以基本上事件接收器让我负责对项目进行任何更改,但这不是 ItemUpdating 的正常行为。有谁知道是什么原因造成的?
public override void ItemUpdating(SPItemEventProperties properties)
{
var recurringBefore = properties.ListItem.TryGetValue<bool>(Constants.CommonFields.Recurring_STATIC);
var recurringAfter = Convert.ToBoolean(properties.AfterProperties[Constants.CommonFields.Recurring_STATIC]);
//This loop is the horrible fix I have done to manually update the relevant fields but this shouldn't be necessary
var item = properties.ListItem;
foreach (SPField key in item.Fields)
{
if (item[key.InternalName] != properties.AfterProperties[key.InternalName] && key.CanBeDisplayedInEditForm && properties.AfterProperties[key.InternalName] != null)
{
//looping through and setting the AfterProperties to what they already are makes them save? If I don't do this nothing saves
properties.AfterProperties[key.InternalName] = properties.AfterProperties[key.InternalName].ToString();
}
}
if (!recurringBefore && recurringAfter &&
currWfStatus == Constants.WorkflowStatus.Processed)
{
//do some stuff
}
base.ItemUpdating(properties);
}
【问题讨论】:
-
您是否尝试过在函数覆盖的开头而不是结尾调用
base.ItemUpdating(properties)? -
是的,没有区别。
标签: c# sharepoint-2010 event-receiver