Ask a questionAsk a question
 

AnswerSharepoint Event Handler stops trigger/firing

  • Sunday, November 01, 2009 5:29 PMff4930 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Hi,

    I have an item adding event handler attached to a list.  This event handler was working working for a month, and today it just stopped working.

    The event handler just accesses the root folder's properties collections list and retrieves a value, updates it and stores it back.

    Here is a snippet of the code:
    SPSecurity.RunWithElevatedPrivileges(delegate()
                        {
                            using (SPSite siteColl= new SPSite("http://someurl/"))
                            {
                                using (SPWeb currentSite = siteColl.OpenWeb())
                                {
                                    //get the start counter
                                    int startCounter = 0;
                                    //allow any user to update
                                    currentSite.AllowUnsafeUpdates = true;
                                    //get current list
                                    SPList currentList = currentSite.Lists["Projects"];
    
                                    //if it doesnt contain the job number key add it with the custom job number
                                    if (!currentList.RootFolder.Properties.ContainsKey("JobNumberCounter"))
                                    {
                                        currentList.RootFolder.Properties.Add("JobNumberCounter", "2224");
                                    }
    
                                    //parse the counter to a number
                                    startCounter = int.Parse(currentList.RootFolder.Properties["JobNumberCounter"].ToString());
    
                                    //if regular job -- generate auto increment job number
                                    if (jobType.Equals("Job"))
                                    {
                                        ++startCounter;
                                        properties.AfterProperties[jobNumberInternalName] = startCounter;
    
                                        currentList.RootFolder.Properties["JobNumberCounter"] = startCounter.ToString();
                                        currentList.RootFolder.Update();
                                    }
    

    Does anyone know why this is happening?  Is retrieving and updating the root folder's properties collection not reliable?  This worked for a month and suddenly today it stopped. 

Answers

All Replies