积极答复者
关于ItemAdding不能取消增加的动作

问题
-
我现在写了一个 SPItemEventReceiver里面重写了一个ItemAdding,我希望当我判断符合了一定的条件话就不让他增加了,并且报出错误的原因。
我现在是模仿ItemDeleting里面写的,貌似没什么作用.
public override void ItemAdding(SPItemEventProperties properties)
{
if(XXXX)
{
properties.ErrorMessage = "此时间段内已被确定使用!";
properties.Cancel = true;
}
}
如果像工作流那样直接删除的话感觉不是太好,我希望报出那个错误信息。不知道可有什么方法。
难道只有ItemDeleting可以取消删除,ItemAdding不能取消增加的动作?
答案
全部回复
-
我测试ItemAdding是可以被properties.Cancel = true取消增加的动作的。
public override void ItemAdding(SPItemEventProperties properties)
{
properties.Cancel = true;
properties.ErrorMessage = "Adding Cancelled";
//base.ItemAdding(properties);
}
所以检查下if条件。
另外,这是开发问题,发错地方了。
-lambert上善若水中文Blog: SharePoint in My Eyes