문제

문서 라이브러리의 경우 항목 업데이트 이벤트 수신기가 두 번 실행되는 이유는 체크인/체크아웃 때문입니다.

또한 이 항목 업데이트 이벤트로 현재 항목 값을 업데이트하는 경우 문서 라이브러리/목록의 경우 두 번 실행될 수 있습니다.

코드를 통해 이 두 가지 경우를 어떻게 처리할 수 있나요?

도움이 되었습니까?

해결책

당신이 두 번째를 유발하는 시나리오의 경우 ItemUpdating 아이템 값을 변경하면 다음을 사용할 수 있습니다. EventFiringEnabled 매개변수( try - catch -finally 주변):

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

다른 시나리오는 더 어렵습니다. 제가 이 시나리오를 사용하는 이유는 다음과 같습니다. 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-temupdated-events-firing-twice-in-a-sharePoint-tem- 수신기 /

@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