Tips and tricks for .NET using ASP and VB code.

Add an Outlook calender item with code

Public Class ThisAddIn

    Public WithEvents PublicOutlookInspectors As Outlook.Inspectors

    Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
        NewOutlookAppointmentUsingCreateItem()
    End Sub

    Private Sub NewOutlookAppointmentUsingCreateItem()
        Dim OutlookApplication As New Outlook.Application
        Dim OutlookAppointmentItem As Outlook.AppointmentItem = OutlookApplication.CreateItem(Outlook.OlItemType.olAppointmentItem)
        If OutlookAppointmentItem IsNot Nothing Then
            OutlookAppointmentItem.Recipients.Add("User.Name@Sample.Com")
            OutlookAppointmentItem.Body = "Test Outlook appointment generated by code."
            OutlookAppointmentItem.Subject = "Test Outlook appointment generated by code."
            OutlookAppointmentItem.Location = "Test Outlook appointment generated by code."
            OutlookAppointmentItem.Start = Now.AddHours(1)
            OutlookAppointmentItem.End = Now.AddHours(2)
            OutlookAppointmentItem.Importance = Outlook.OlImportance.olImportanceNormal
            OutlookAppointmentItem.RequiredAttendees = OutlookAppointmentItem.Organizer
            OutlookAppointmentItem.Display(True)
            Try
                OutlookAppointmentItem.Save()
                Runtime.InteropServices.Marshal.ReleaseComObject(OutlookAppointmentItem)
            Catch
            End Try
        End If
    End Sub

End Class

No comments:

Post a Comment

Search This Blog