CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2006
    Posts
    199

    COM Interop problem with Outlook on recurring days

    I'm writing a class to retrieve Outlook appointments. It must include recurring days.

    With this code:
    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.

  2. #2
    Join Date
    Sep 2006
    Posts
    199

    Re: COM Interop problem with Outlook on recurring days

    bump... anyone have any ideas on this? thx

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: COM Interop problem with Outlook on recurring days

    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#" .

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

    Code:
    // 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:

    Code:
    // 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

    Code:
    //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.

  4. #4
    Join Date
    Sep 2006
    Posts
    199

    Makes no difference

    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?

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Makes no difference

    Quote Originally Posted by purpleflash
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured