Is there a way to stop OnItemSaving events?
You can do it with EventDisabler
:
using (new EventDisabler())
{
item.Editing.BeginEdit();
item.Editing.EndEdit();
}
Found here: Temporarily Disabling Events Via Sitecore API
source to share
To expand on @Ruud van Falier's answer, it's worth noting that EventDisabler
, like SecurityDisable
, inherits from IDisposable
. Thus, you can create a property or local variable that is EventDisabler
, and Sitecore events will be disabled from the time the variable or property is initialized until the time the method is called Dispose()
.
For example, in the following class, events will be disabled from the time the method is called Foo()
until the time the method is called Bar()
.
public class SomeClass
{
private EventDisabler _eventDisabler;
...
public void ToggleEventDisabler(bool eventDisablerOn)
{
_eventDisabler = eventDisablerOn ? new EventDisabler() : null;
}
public void Foo()
{
ToggleEventDisabler(true); //turn on the event disabler
...do stuff...
}
public void Bar()
{
...do stuff...
if (_eventDisabler != null)
{
_eventDisabler.Dispose();
}
}
}
source to share