Delete Single Occurrence of Recurring Appointments

Add-in Express™ Support Service
That's what is more important than anything else

Delete Single Occurrence of Recurring Appointments
 
Ling Kiin




Posts: 10
Joined: 2017-02-28
How do I cancel deletion using CancelEventArgs when user try to delete single occurrence of recurring appointments?

I am able to cancel the deletion if it is a not recurring appointment or user deleting whole series of recurrences.

* I can see the ItemChange & ProcessItemChange events been triggered, but I am unable to the cancel the delete event.
Posted 27 Mar, 2017 02:54:18 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
Hello Ling,

You can use an Outlook Items (not Item!) Events class to handle the BeforeItemMove event of the calendar folder.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 27 Mar, 2017 04:50:18 Top
Ling Kiin




Posts: 10
Joined: 2017-02-28
BeforeItemMove only work for single appointment or entire series of recurrence but not single occurrence of the recurrence.
Posted 27 Mar, 2017 05:35:19 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
Hello Ling,

Sorry for delay; I try to invent a way to solve this task.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 28 Mar, 2017 08:34:40 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
Hello Ling,

You need to connect to events of that item and cancel the BeforeDelete event; see https://msdn.microsoft.com/en-us/library/office/ff869458.aspx. To achieve this, add an Outlook Item (not Items!) Events class to your project, create an instance of the class, connect it to the item which is the source of events, and handle the ProcessBeforeDelete method.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 29 Mar, 2017 06:48:42 Top
Ling Kiin




Posts: 10
Joined: 2017-02-28
Does the Outlook Item (not Items) event class has ProcessBeforeDelete method?
Do you have the example of the ProcessBeforeDelete method?
Posted 29 Mar, 2017 06:54:36 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
You need to add an Outlook Item (not Items!) Events class to your project, open the class, and find the ProcessDelete method.

I don't have such an example. The simplest test would be to write e.Cancel = true in that method.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 29 Mar, 2017 06:57:25 Top
Ling Kiin




Posts: 10
Joined: 2017-02-28
Thanks for your reply.

I tried the ProcessBeforeDelete method, it is only working when the appointment item been opened and connected to the OutlookItemEvents class.

If user click the appointment item without open it and press delete, the method will not be called (the selected item is not connected)
Posted 29 Mar, 2017 22:05:01 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
Hi Ling,

The code below works fine for me.

Add-in module:
Dictionary<string, OutlookItemEventsClass1> dic = new Dictionary<string, OutlookItemEventsClass1>();
private void adxOutlookAppEvents1_ExplorerSelectionChange(object sender, object explorer) {
    System.Diagnostics.Debug.WriteLine("!!! adxOutlookAppEvents1_ExplorerSelectionChange");
    foreach (OutlookItemEventsClass1 eventsObject in dic.Values) {
        eventsObject.RemoveConnection();
    }
    dic.Clear();
    Outlook.Selection sel = null;
    try {
        sel = (explorer as Outlook._Explorer).Selection;
    } catch (Exception ex) { }
    System.Diagnostics.Debug.WriteLine("!!! adxOutlookAppEvents1_ExplorerSelectionChange. cleared");
    if (sel == null) return;
    System.Diagnostics.Debug.WriteLine("!!! adxOutlookAppEvents1_ExplorerSelectionChange. start populating");
    for (int i = 1; i <= sel.Count; i++) {
        object item = sel[i];
        OutlookItemEventsClass1 eventsObject = new OutlookItemEventsClass1(this);
        eventsObject.ConnectTo(item, eventClassReleasesComObject: true);
        dic.Add(eventsObject.EntryID, eventsObject);
    }
    System.Diagnostics.Debug.WriteLine("!!! adxOutlookAppEvents1_ExplorerSelectionChange. dic.Count=" + dic.Count.ToString());
}


Events class:

public string EntryID { get; private set; }

public override bool ConnectTo(object olItem, bool eventClassReleasesComObject) {

    if (olItem is Outlook._AppointmentItem) {
        EntryID = (olItem as Outlook._AppointmentItem).EntryID;
        System.Diagnostics.Debug.WriteLine("!!! OutlookItemEventsClass1. ConnectTo. " + (olItem as Outlook._AppointmentItem).Start.ToString());
    } else if (olItem is Outlook._MailItem) {
        EntryID = (olItem as Outlook._MailItem).EntryID;
    }
    return base.ConnectTo(olItem, eventClassReleasesComObject);
}

public override void ProcessBeforeDelete(object item, AddinExpress.MSO.ADXCancelEventArgs e) {
    System.Diagnostics.Debug.WriteLine("!!! ProcessBeforeDelete");
    e.Cancel = true;
}


Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 30 Mar, 2017 06:45:55 Top