private static void EventFiringEnabled(bool
enabled)
{
Assembly assembly = Assembly.Load("Microsoft.Sharepoint,
Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
Type type = assembly.GetType("Microsoft.SharePoint.SPEventManager");
PropertyInfo pi = type.GetProperty("EventFiringDisabled",
System.Reflection.BindingFlags.Static |
System.Reflection.BindingFlags.NonPublic);
pi.SetValue(null,
!enabled, null);
} In the next post, I'll show you how to detect all event receivers in your project.
Another great reference. Quick question, since disabling the event receivers from within the event receiver is per thread is this also per thread?
ReplyDeleteI think that it is, but I can't say for sure.
DeleteAn alternative for a reusable class is as follows:
ReplyDeletepublic class DisableEventScope : SPItemEventReceiver, IDisposable
{
bool previousState;
public DisableEventScope()
{
previousState = base.EventFiringEnabled;
base.EventFiringEnabled = false;
}
public void Dispose()
{
base.EventFiringEnabled = previousState;
}
}
To use:
using (DisableEventScope scope = new DisableEventScope())
{
//Actions to be performed without triggering event handlers
}
Thanks, I will try that.
Delete