How to: Programmatically delete appointments
Applies to: Visual Studio Visual Studio for Mac
Note
This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
This example deletes one instance of a recurring appointment. The example assumes that an instance of a recurring appointment occurs on June 28, 2006, at 08:00.
Applies to: The information in this topic applies to VSTO Add-in projects for Outlook. For more information, see Features available by Office application and project type.
Example
Private Sub ThisAddIn_Startup(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Startup
Dim calendar As Outlook.MAPIFolder = _
Application.Session.GetDefaultFolder( _
Outlook.OlDefaultFolders.olFolderCalendar)
Dim calendarItems As Outlook.Items = calendar.Items
Dim item As Outlook.AppointmentItem = TryCast( _
calendarItems("Test Appointment"), Outlook.AppointmentItem)
Dim pattern As Outlook.RecurrencePattern = _
item.GetRecurrencePattern()
Dim itemDelete As Outlook.AppointmentItem = _
pattern.GetOccurrence(New Date(2006, 6, 28, 8, 0, 0))
If itemDelete IsNot Nothing Then
itemDelete.Delete()
End If
End Sub
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Outlook.MAPIFolder calendar =
Application.Session.GetDefaultFolder(
Outlook.OlDefaultFolders.olFolderCalendar);
Outlook.Items calendarItems = calendar.Items;
Outlook.AppointmentItem item =
calendarItems["Test Appointment"] as Outlook.AppointmentItem;
Outlook.RecurrencePattern pattern =
item.GetRecurrencePattern();
Outlook.AppointmentItem itemDelete = pattern.
GetOccurrence(new DateTime(2006, 6, 28, 8, 0, 0));
if (itemDelete != null)
{
itemDelete.Delete();
}
}