Temporarily disable events through the Sitecore API

21 december 2012 om 00:00 by Martijn van der Put - Post a comment

This is just a quick blog-post about temporarily disabling local events through the Sitecore API.

When writing your code you might come to a point where you for example calling a method which finally result in triggering a (custom) Sitecore event.
For example, the Item.Editing.EndEdit() method.
This method contains an overload which contains a param: EndEdit(bool silent)

Setting this param to true results in calling the ItemManager.SaveItem method inside this using clause:

using (new EventDisabler())
{
  ItemManager.SaveItem();
}

Looking at this code, it is also possible to use the using clause at other positions in your code where you have the need to temporarily disable the events that normally will be triggered.

using (new EventDisabler())
{
  // Your custom code without temprarily triggering events
}

Nieuwste