使用 SharePoint 2010 RC 我在使用事件接收器取消删除列表项时遇到问题。我的代码正在触发、设置 SPItemEventProperties 的取消属性、设置错误消息并将错误返回给调用线程。这种方法在添加/更新方法中运行良好,但是,在删除方法中使用时,我可以在调试器中看到代码触发,但该项目仍被移动到站点的回收站。
此外,我在从 stsadm 的“CMSPUBLISHINGSITE#2”模板创建的站点中看到了这种行为,而不是从通过管理中心从“团队站点”模板创建的站点中看到的。
行为不端的代码如下:
public override void ItemDeleting(SPItemEventProperties properties)
{
if (!(properties.UserLoginName == "SHAREPOINT\\system"))
{
try
{
throw new CreatorIdAliasingException("Please contact support if you feel a release web site has been inappropriately assigned to your organization.");
}
catch (CreatorIdAliasingException ex)
{
properties.Cancel = true;
properties.ErrorMessage = ex.ToString();
properties.InvalidateListItem();
throw;
}
}
}
作为参考,ItemAdding 方法中包含相同的代码并按预期工作。
public override void ItemAdding(SPItemEventProperties properties)
{
base.ItemAdding(properties);
if (!(properties.UserLoginName == "SHAREPOINT\\system"))
{
try
{
throw new InvalidCreatorIdException("Please contact support to add a known URL to your list of release web sites.");
}
catch (InvalidCreatorIdException ex)
{
properties.Cancel = true;
properties.ErrorMessage = ex.ToString();
properties.InvalidateListItem();
throw;
}
}
}