Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Calling this.EventFiringEnabled inside a console application, will it disable the Event Firing for all users , or just during the console app execution

$
0
0

I have the following console application inside my sharepoint 2013:-

  public class HandleEventFiring : SPItemEventReceiver
    {

        public void DisableHandleEventFiring()
        {

            this.EventFiringEnabled = false;
        }

        public void EnableHandleEventFiring()
        {
            this.EventFiringEnabled = true;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
           using (SPSite site = new SPSite("http://***/"))
            {
                using (SPWeb web = site.OpenWeb("Sites"))
                {
                    SPWebCollection subWebs = web.Webs;

                    foreach (SPWeb subSite in subWebs)
                    {
                        string subsitename = subSite.Title.Replace("/", " ").Trim();
                        HandleEventFiring handleEventFiring = new HandleEventFiring();
                        try
                        {

                            SPGroup group = web.SiteGroups[subsitename];
                            SPList managerList = subSite.Lists.TryGetList("ManagerTasks");
                            SPFieldUserValueCollection values = new SPFieldUserValueCollection();
                            foreach (SPUser user2 in group.Users)
                            {
                                values.Add(new SPFieldUserValue(web, user2.ID, user2.Name));

                            }
                            foreach (SPListItem item in managerList.Items)
                            {
                                noofitems++;

                                item["Managers"] = values;

                                handleEventFiring.DisableHandleEventFiring();
                                item.SystemUpdate();
                                handleEventFiring.EnableHandleEventFiring();

                            }



                        }
                        catch (Exception e)
                        {

                            exceptionoutput = exceptionoutput + subsitename+"  ";
                            continue;
                        }
                        finally
                        {
                            handleEventFiring.EnableHandleEventFiring();

                        }
                    }


                }

            }


        }
    }

I am looping through a group of sub-sites, and then inside each sub-site i am looping through a list of items and update some columns for the items. now i want to disable firing any event receiver which get fired as a result of calling item.SystemUpdate(); inside my above app. but i am not sure how often i need to call EventFiringEnabled = false; & EventFiringEnabled = true; ?. i mean due i need to call this per item update, or it is enough to call EventFiringEnabled = false; at the beginning of the console application and then call EventFiringEnabled = true; at the end ? or i need to call these 2 methods for each item separately?

second question , let say i am calling EventFiringEnabled = false;, without enabling it again.. so does this mean that the event receivers will be disabled for the items or lists even if someone try to update/create an item inside the sharepoint sites ?? or the scope/effect of these method are within the console app only ?

third question. when i am calling this.EventFiringEnabled=false inside a console application, will it disable the Event Firing for all users (who might be updating items during the console app execution for the same list) , or calling this.EventFiringEnabled=false will affect the console pp execution only?


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>