How to: Share Free/Busy Schedule Within a Specified Period in a Calendar

Office 2013 and later

This example obtains the free/busy schedule within a specified week from a calendar and displays the free, busy, and subject details to the user.

This code sample uses the GetCalendarExporter method of the Folder object to obtain a CalendarSharing object for the default Calendar folder for a specific one-week period. It then calls the ForwardAsICal method on the CalendarSharing object and displays the message with an iCalendar payload.

If you use Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 15.0 Object Library component and specify the Outlook variable when you import the Microsoft.Office.Interop.Outlook namespace. The Imports or using statement must not occur directly before the functions in the code example but must be added before the public Class declaration. The following lines of code show how to do the import and assignment in Visual Basic and C#.

using Outlook = Microsoft.Office.Interop.Outlook;
private void DemoCalendarSharing()
    // Get instance of CalendarSharing object
    Outlook.CalendarSharing calShare =
    // Free busy and subject details
    calShare.CalendarDetail =
    // Set start and end dates
    calShare.StartDate = DateTime.Today;
    calShare.EndDate = calShare.StartDate.AddDays(1);
    // Call ForwardAsICal method
    Outlook.MailItem mail =
    // Add recipient
    // Set subject
    string CalName =
    mail.Subject =
        Application.Session.CurrentUser.Name +
        CalName.PadLeft(CalName.Length + 1);
    // Display calendar sharing item

Other resources