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;
}
}
}