views:

361

answers:

1

In my Outlook Add-in I want to be able to filter my default calendar for appointments that have the following criteria:

  1. all-day events = true
  2. reminders set = true

I have figured out how to use DASL to search for those items, but how do I get the calendar view to show those filtered results?

Here is the code I have so far:

internal class MyAppointment : Appointment
{
    [OutlookItemProperty("urn:schemas:calendar:dtstart")]
    public DateTime Start { get { return Item.Start; } }

    [OutlookItemProperty("urn:schemas:calendar:dtend")]
    public DateTime End { get { return Item.End; } }

    public bool ReminderSet { get { return Item.ReminderSet; } }

    public bool AllDayEvent { get { return Item.AllDayEvent; } }
}


void btnFix_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
{
    Outlook.Folder folder = (Outlook.Folder)Globals.ThisAddIn.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);

    var appts = from item in folder.Items.AsQueryable<MyAppointment>()
                where item.Start >= DateTime.Now
                && item.End <= DateTime.Now.AddMonths(1)
                && item.ReminderSet
                && item.AllDayEvent
                select item.Item;

    // bind to Calendar view???
}

I now have a collection of Appointments. How do I get the calendar to show them?

A: 

The answer should anyone require it:.

  1. Build the query as a string filter.
  2. Apply it as a filter to the Calendar folder.

    Outlook.CalendarView view = (Outlook.CalendarView)Application.ActiveExplorer().CurrentView; filter = "\"urn:schemas:calendar:alldayevent\" = 1 AND \"http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8503000b\" = 1";

    view.Filter = filter; view.Apply();

Junto