ItemUpdatingをオーバーライドするイベント受信者を持つカスタムリスト定義があります。リストにはコンテンツ承認が有効になり、と一緒にメジャーとマイナーバージョンを作成します。ItemUpdatingのSPListItemフィールドをSystemUpdateで永続化しない(false)
アイテムが承認されている場合は、バージョンと承認ステータスに影響を与えずにブール値フィールド(公開されていますか?)を設定します。私は理解するSystemUpdate(偽)はこれを行うと思われますが、それはboolの値を保持しません。私は更新()またはSystemUpdateを()使用している場合は、値が永続化されるが、それは承認に承認ステータスを設定しないと、次のエラーがスローされます。
The file [filename] has been modified by [user] on [date].
public override void ItemUpdating(SPItemEventProperties properties)
{
base.ItemUpdating(properties);
EventFiringEnabled = false;
try
{
if (IsChangingToApproved(properties))
{
if (!Validate(properties))
{// This person can't approve
properties.ErrorMessage = "You don't have appropriate permissions.";
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.Cancel = true;
}
else
{// Set the IsPublished flag to true
var isPublishedField = properties.List.Fields["Is Published?"];
if (isPublishedField != null)
{
properties.ListItem[isPublishedField.InternalName] = true;
// Doesn't update bool, ItemUpdating event functions normally
properties.ListItem.SystemUpdate(false);
// Updates bool, but ItemUpdating event does not complete
//properties.ListItem.Update();
//properties.ListItem.SystemUpdate();
}
}
}
}
catch (Exception ex) { return; }
finally { EventFiringEnabled = true; }
}
物事I試みました:
- プロパティから項目を更新する代わりに
using Site/using Web
ブロックでlistItemを更新しています。 - properties.AfterProperties ["Is Published?"]フィールドを設定します。
同期イベント内で更新することは間違いありません。私はAfterPropertiesの設定が私のために働いていなかったので、非同期ItemUpdatedイベントに行った。あなたの答えを正しいものとしてマークしています。 – rboone
私は助けてくれると嬉しかった:)レシーバーは把握が容易ではなく、SharePointで数年間働いていても毎日学んでいる。あなたのプロジェクトに幸運。 –