質問

ドキュメント ライブラリの場合にアイテム更新イベント レシーバーが 2 回起動する理由は、チェックイン/チェックアウトのためです。

また、この項目更新イベントで現在の項目値を更新している場合、ドキュメント ライブラリ/リストの場合は 2 回起動する可能性があります。

これら両方のケースをコード経由で処理するにはどうすればよいでしょうか?

役に立ちましたか?

解決

あなたが 2 番目のトリガーを行うシナリオの場合 ItemUpdating 項目の値を変更すると、 EventFiringEnabled パラメータ ( try - catch -finally その周りに):

this.EventFiringEnabled = false;
// Do the changes
item.Update();
this.EventFiringEnabled = true;

もう 1 つのシナリオはより困難であり、私がこのシナリオを使用する背後にある理由 ItemUpdated 可能な限り代わりに!

を確認できます BeforeProperties, ListItem そして AfterPropertiesあなたの中で ItemUpdating イベント レシーバーを使用して、アクションを実行する必要がある更新が行われているかどうかを確認します。そうでない場合は、ただ return.

こちらがガイドです 使えるときのために .BeforePropertiesそしていつ入るべきか .ListItem その代わり

他のヒント

public override void ItemUpdating(SPItemEventProperties properties)
{
  try
  {
    //is the item checked out?
    if (isCheckin(properties) == false)
    {
         this.EventFiringEnabled = false;

         //do your stuff

    }
  }
  catch(Exception a)
  {
    //catch any errors
  }
  finally
  {
    this.EventFiringEnabled = true; 
  }
} 

private bool isCheckin(SPItemEventProperties properties)
{
    if (properties.AfterProperties["vti_sourcecontrolcheckedoutby"] == null 
         && properties.BeforeProperties["vti_sourcecontrolcheckedoutby"] != null)
    {
        return true;
    }
    return false;
}
.

https://www.simple-talk.com/dotnet/.net-tools/managing-itemupdating-and-iteMupdated-events-firing-twice-in-a-SharePoint-item-Event-Receiver /

@Robert前のプロパティについてはい、あなたの右に彼らは関係がありません....私が考えることができる可能な解決策のみ

private bool isCheckin(SPItemEventProperties properties)
{
    string BeforeVal = properties.ListItem["vti_sourcecontrolcheckedoutby"];

    if (properties.AfterProperties["vti_sourcecontrolcheckedoutby"] == null 
         && BeforeVal != null)
    {
        return true;
    }
    return false;
}
.

ライセンス: CC-BY-SA帰属
所属していません sharepoint.stackexchange
scroll top