3

I have a client windows application that is uploading many rows of data to a list. However, I don't want the event handler on the list to fire while rows are being added via the windows application.

Is there a way in the Client Object Model to disable, or remove and add the list event handler?

Thanks.

0

If you create a web service as @moontear suggest you can use this solution by Adrian Henke to update items without triggering events:

public class SPListItemExtensions : SPItemEventReceiver, IDisposable
{
    private readonly bool _oldValue;

    public SPListItemExtensions()
    {
        _oldValue = EventFiringEnabled;
        EventFiringEnabled = false;
    }

    #region IDisposable Members

    public void Dispose()
    {
        EventFiringEnabled = _oldValue;
    }

    #endregion
}

Usage:

using (new SPListItemExtensions())
{
    item.Update();
}

Referenses:
https://stackoverflow.com/a/2468156
http://adrianhenke.wordpress.com/2010/01/29/disable-item-events-firing-during-item-update/

4

Unfortunately you will not be able to access the event receivers using the COM.

See the MSDN documentation on the SP.List object. Your only chance would be to develop some kind of custom webservice which you could call from you client code and which disables the event receiver temorarily.

1

@eirikb: Unfortunately, there is a "minor" problem with this approach. Although it is not well documented, the property has (wisely) no global effect. It does not disable all of the event receivers in the farm, nor does does it disable triggering event receivers in the current list for activities occured on other threads. It has a scope local to the current tread. See this answer for reference. What does it mean for us? If you create and call a custom web service that sets the EventFiringEnabled property, it has effect only in the scope ot that call, but has no effect at all of your code executed from the client object model.

Is there a way in the Client Object Model to disable, or remove and add the list event handler?

So as far as I know, you cannot disable the event receiver from the client object model. But in SP 2013 you can remove and add the event receiver. If you need to limit the effect of this change to your current process, use this approach only if you are absolutely sure your process is the only one that alters data in your list!

To remove, you should call the deleteObject method of the corresponding SP.EventReceiverDefinition instance.

List list = web.Lists.GetById(listId);
EventReceiverDefinition eventReceiver = list.EventReceivers.GetById(yourEventReceiverId);
eventReceiver.DeleteObject();
clientContext.ExecuteQuery();

You can add a new handler via the add method of the SP.EventReceiverDefinitionCollection, passing an SP.EventReceiverDefinitionCreationInformation instance as parameter.

List list = web.Lists.GetById(listId);
list.EventReceivers.Add(new EventReceiverDefinitionCreationInformation {
    EventType = EventReceiverType.ItemUpdated,
    ReceiverName = "MyRemoteEventReceiverItemUpdated",
    ReceiverClass = "Your.Namespace.YourClass",
    ReceiverAssembly = "Strong Name Of Your Assembly",
    SequenceNumber = 10000}
);
list.Update();
clientContext.ExecuteQuery();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.