0

I created a event receiver on Item-deleting to send email when a listitems in the calendar is being deleted. However, item-deleting is not triggered when a single occurrence of a recurring event is being deleted. Instead Item_updating is being triggered. I am wondering from the properties, which one I specifies the action as a "Deletion"?

1

I resolved the same problem... Try this:

    /// <summary>
    /// An item is being updated.
    /// </summary>
    public override void ItemUpdating(SPItemEventProperties properties)
    {
        base.ItemUpdating(properties);

        //Se o evento tiver sido excluído.
        if (properties.AfterProperties["Title"] != null)
        {
            if (properties.AfterProperties["Title"].ToString().Contains("Excluído:"))
            {
                SPListItem item = properties.ListItem;
                DeleteRecurrenceEvents(item);
            }
        }
    }

    /// <summary>
    /// Garante que quando um evento recorrente for deletado, todas as suas recorrências também serão.
    /// </summary>
    /// <param name="item"></param>
    public void DeleteRecurrenceEvents(SPListItem item)
    {
        try
        {
            if (item["fRecurrence"] != null)
            {
                if (bool.Parse(item["fRecurrence"].ToString()))
                {
                    //Deletar Eventos Recorrentes com mesmo Título.
                    SPQuery query = new SPQuery();
                    query.Query = string.Format(@"<Where>
                                                     <Eq>
                                                         <FieldRef Name='Title'/>
                                                         <Value Type='Text'>{0}</Value>
                                                     </Eq>
                                                  </Where>", item.Title);

                    SPListItemCollection colitems = item.ParentList.GetItems(query);
                    for (int i = 0; i < colitems.Count ; i++ )
                    {
                        colitems[i].Delete();
                    }
                }
            }
        }
        catch (Exception ex)
        {
            throw new Exception("Erro: " + ex.Message);
        }
    }
0

In the ItemUpdating event, compare the contents of the ListItem property (which will hold the pre-edit values of the item), with the contents of the AfterProperties property (which should hold the post-edit values of the item.)

I expect all of the recurrences might be squished into a single listitem, so you'll have to manually determine if there are any values missing in the post-edit version.

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.