Saturday, November 11, 2006

VSTO Recurring appointments in Outlook

Doing a small Visual Studio for Office based Outlook plug-in. I stumbled over the following problem with recurring appointments

The standard approach is to do the following to include recurring appointments into your resultset.

string searchfilter1 =
string.Format("[Start] >= '{0}' AND [Start] < '{1}'","01/11/2004", "01/12/2006");
Outlook.Items result1 = calendar.Items.Restrict(searchfilter1);
result1.Sort("[Start]", false);
result1.IncludeRecurrences = true;
The problem that I ran into was that only appointments created within the span of my restriction showed up. So when searching for appointments in November a recurring appointment created before November did not show up.

Remembering the fact that searches are fast and item retrieval is slow I came up with the following solution.

string searchfilter1 =
string.Format("[Start] >= '{0}' AND [Start] < '{1}'","01/01/2004", "01/12/2006");
Outlook.Items result1 = calendar.Items.Restrict(searchfilter1);
result1.Sort("[Start]", false);
result1.IncludeRecurrences = true;
string searchfilter2 =
string.Format("[Start] >= '{0}' AND [Start] < '{1}'","01/11/2004", "01/12/2006");
Outlook.Items result2 = result1.Restrict(searchfilter2);

result2.Sort("[Start]", false);
result2.IncludeRecurrences = true;
Basically I searched back a couple of years and then applied my real search criteria to the resultset.

Welcome to myself

Never caught the first wave of blogging, were too cool for the second wave, but now I guess that there is no way around getting a net presence.