Udostępnij za pośrednictwem


How to: Delete Appointments

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Application-level projects

Microsoft Office version

  • Outlook 2003

  • Outlook 2007

For more information, see Features Available by Application and Project Type.

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.

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();
    }
}

See Also

Tasks

How to: Create Appointments

How to: Create a Custom Calendar

How to: Create a Meeting Request

Concepts

Working with Calendar Items

Getting Started Programming Application-Level Add-Ins