Click to See Complete Forum and Search --> : COM Interop problem with Outlook on recurring days


purpleflash
February 17th, 2008, 05:10 PM
I'm writing a class to retrieve Outlook appointments. It must include recurring days.

With this code:

// Get the Inbox folder.
MAPIFolder oCal;
if (!local)
{
oCal = oNS.GetSharedDefaultFolder(rec, OlDefaultFolders.olFolderCalendar); // use anyone's profile
}
else
{
oCal = oNS.GetDefaultFolder(OlDefaultFolders.olFolderCalendar); // using only own profile
}

//Get the Items collection in the Appointment folder, filtered by the query.
Items oItems = oCal.Items;
oItems.IncludeRecurrences = true;
oItems = oCal.Items.Restrict(filter);


It works, IF the date of the 1st instance of the recurring appointment happens to be within the filter... but it does not work if the 1st instance is outside the filter parameters.

For instance, suppose I have this filter:
[Start]>=03/01/2008 and [End]<=03/15/2008

and there is a recurring appointment set up such as:

03/05/2008
03/10/2008

It will return both of these. However, if there are 3 instances like this:
02/26/2008
03/05/2008
03/10/2008

none are returned, because the [Start] is before 03/01/2008, EVEN THOUGH two of the appointment instances DO fall inside the filter criteria..

To me this makes no sense... it should return those appointment dates that fall between the start and end of the filter, even though there are some that are before the Start date and maybe some after the End date...

Any solutions, from those who have done this type out Outlook work?

thx.

purpleflash
February 20th, 2008, 04:29 PM
bump... anyone have any ideas on this? thx

Arjay
February 20th, 2008, 05:19 PM
I haven't done this directly, but in looking into it, I found the KB article: "How to retrieve specific messages by using the Find method and Restrict method in Visual C#" (http://support.microsoft.com/kb/310265).

In this article, the code sorts the items by [Start] prior to filtering the items with Restrict.


// Get the Items collection in the folder.
Outlook.Items oItems = (Outlook.Items)oCalendar.Items;
Console.WriteLine("Total Items (unrestricted): " + oItems.Count);

//Include all occurrences of recurring items, and then sort them.
oItems.Sort ("[Start]", false);
oItems.IncludeRecurrences = true;

Then it restricts the items:

// Define the string for the search criteria.
String sCriteria;

// Set the criteria for the Date fields.
sCriteria = "[Start] <= '09/01/2002 08:00 AM' and [End] >= '2/15/2002 08:00 PM'";

// Use the Restrict method to reduce the number of items to process.
Outlook.Items oRestrictedItems = oItems.Restrict(sCriteria);
oRestrictedItems.Sort ("[Start]", false);
oRestrictedItems.IncludeRecurrences = true;

Finally it uses the restricted list

//Get each item until item is null.
Outlook.AppointmentItem oAppt;
oAppt = (Outlook.AppointmentItem)oRestrictedItems.GetFirst();
while (oAppt != null)
{

}

I noticed that you weren't doing the initial sorting.

Hope this helps.

purpleflash
February 28th, 2008, 05:29 PM
Even if you have recurring dates that fall in between the Start and End filter, unless the 1st date is also > the Start date it won't be found.

Now, somehow Outlook manages to find them... hmmm. Wonder how?

Arjay
February 28th, 2008, 05:45 PM
Even if you have recurring dates that fall in between the Start and End filter, unless the 1st date is also > the Start date it won't be found.

Now, somehow Outlook manages to find them... hmmm. Wonder how?Did you sort them?