none
How to get recurring calendar item one by one using exchange web service RRS feed

  • Question

  • I had created a recurring appointment in calendar, the start time is 2011-01-04, and it will happen everyday at 16:00 PM, but I cannot get the calendar item if the set the search condition: "From 2011-01-05 to 2011-01-07". If I did not set any search condition, it will only return the first occured calendar item. My question is how to get the recurring calendar item if it will happen in the giving time interval?

    Here is my code:

    // Create the request for all Calendar items between the specified dates
       FindItemType findItemRequest = new FindItemType();
    // Bring back ALL properties on the items returned
       ItemResponseShapeType itemProperties = new ItemResponseShapeType();
       itemProperties.BaseShape = DefaultShapeNamesType.AllProperties;
    findItemRequest.ItemShape = itemProperties;
    
    // We want items from the Calendar "Folder"
       DistinguishedFolderIdType[] folderIDs = { new DistinguishedFolderIdType { Id = DistinguishedFolderIdNameType.calendar } };
       findItemRequest.ParentFolderIds = folderIDs;
    
    //Add date time restriction
    
    DateTime utcDateTimeStart = new DateTime(2011, 1, 4);
          DateTime utcDateTimeEnd = new DateTime(2011, 1, 5);
    
    // This is the filter object that we will associate with the request
          RestrictionType restriction = new RestrictionType();
          // Use And type since there are multiple filter condition
          AndType filterType = new AndType();
    
          // Apply start date filtering to request
          PathToUnindexedFieldType startDateProperty = new PathToUnindexedFieldType();
          startDateProperty.FieldURI = UnindexedFieldURIType.calendarStart;
          FieldURIOrConstantType startDateValue = new FieldURIOrConstantType();
          startDateValue.Item = new ConstantValueType();
          (startDateValue.Item as ConstantValueType).Value = utcDateTimeStart.ToUniversalTime().ToString("yyyy-MM-ddThh:mm:ssZ");
          IsGreaterThanOrEqualToType startDateIsGreaterThanOrEqualTo = new IsGreaterThanOrEqualToType();
          startDateIsGreaterThanOrEqualTo.Item = startDateProperty;
          startDateIsGreaterThanOrEqualTo.FieldURIOrConstant = startDateValue;
    
          // Apply end date filtering to request
          PathToUnindexedFieldType endDateProperty = new PathToUnindexedFieldType();
          endDateProperty.FieldURI = UnindexedFieldURIType.calendarEnd;
          FieldURIOrConstantType endDateValue = new FieldURIOrConstantType();
          endDateValue.Item = new ConstantValueType();
          (endDateValue.Item as ConstantValueType).Value = utcDateTimeEnd.ToUniversalTime().ToString("yyyy-MM-ddThh:mm:ssZ");
          IsLessThanOrEqualToType endDateIsLessThanOrEqualTo = new IsLessThanOrEqualToType();
          endDateIsLessThanOrEqualTo.Item = endDateProperty;
          endDateIsLessThanOrEqualTo.FieldURIOrConstant = endDateValue;
    
    filterType.Items = new SearchExpressionType[] { startDateIsGreaterThanOrEqualTo,  endDateIsLessThanOrEqualTo };
    
    restriction.Item = filterType;
    findItemRequest.Restriction = restriction;
    
    findItemRequest.Traversal = ItemQueryTraversalType.Shallow;
    
    // Send request, receive response
       FindItemResponseType findItemResponse = _ExchangeBinding.FindItem(findItemRequest);
    
    // Pull the message from the response
       ArrayOfResponseMessagesType responseMessages = findItemResponse.ResponseMessages;
    ResponseMessageType responseMessage = responseMessages.Items[0];
    
    if (responseMessage is FindItemResponseMessageType)
       {
        FindItemResponseMessageType msgType = (responseMessage as FindItemResponseMessageType);
        FindItemParentType parentType = msgType.RootFolder;
    
        object obj = parentType.Item;
        if (obj is ArrayOfRealItemsType)
        {
         ArrayOfRealItemsType items = (obj as ArrayOfRealItemsType);
    
         if (File.Exists(@"D:\Temp\NewResult.txt"))
         {
          File.Delete(@"D:\Temp\NewResult.txt");
         }
         XmlSerializer x = new XmlSerializer(typeof(CalendarItemType));
    
         StreamWriter writer = new StreamWriter(@"D:\Temp\NewResult.txt",
          true, Encoding.UTF8);
    
         foreach (ItemType item in items.Items)
         {
          CalendarItemType calItem = item as CalendarItemType;
    
          MemoryStream stream = new MemoryStream();
          XmlTextWriter xWriter = new XmlTextWriter(stream, Encoding.UTF8);
          x.Serialize(xWriter, calItem);
          stream = (MemoryStream)xWriter.BaseStream;
          string xmlText = Encoding.UTF8.GetString(stream.ToArray());
          writer.WriteLine(xmlText);
    
         }
    
         writer.Close();
        }
       }
    

     I had also tried using http request, it works. But it did not work using exchange web service, anyone can point me out why? Thanks a lot.

    Thursday, January 6, 2011 8:07 AM

Answers

  • Alix,

     

    The FindItem Operation behavior that you described is working as it was designed. By default, only single calendar items and recurring master calendar items are returned. Thus one would have to expand the occurences themselves to find all instances. Review the FindItem Operation note found on this MSDN Page: http://msdn.microsoft.com/en-us/library/aa566107.aspx:

     

    The FindItem operation can return results in a CalendarView element. The CalendarView element returns single calendar items and all occurrences. If a CalendarView is not used, single calendar items and recurring master calendar items are returned. The occurrences must be expanded from the recurring master if a CalendarView is not used.

     

    Upon review of the CalendarView element in question on the CalendarView’s MSDN Page reveals the following remarks:

    If the CalendarView element is specified in a FindItem request, the Web service returns a list of single calendar items and occurrences of recurring calendar items within the range specified by StartDate and EndDate.

    If the CalendarView element is not specified in a FindItem request, the Web service returns a list of single calendar items and recurring master calendar items. Calendar occurrences of a recurring calendar item are not expanded.

    The schema that describes this element is located in the EWS virtual directory of the computer that is running Microsoft Exchange Server 2007 that has the Client Access server role installed.

    To solve your issue, you must present the CalendarView element in the FindItem request to have all occurrences of a recurring calendar item returned in the specified date range.

     

    I hope this information assists you Alix.

     

    Dominic Salemno
    Escalation Engineer

    Open Specifications
    • Proposed as answer by King Salemno Friday, January 7, 2011 6:37 PM
    • Marked as answer by Alix Dong Sunday, January 9, 2011 2:23 PM
    Friday, January 7, 2011 6:35 PM
  • N.Shirato,

    You should review the [MS-OXWSTASK] Specification Documentation and the GetItem Operation in Section 3.1.4.4. The document itself discusses the Tasks Web Service Protocol Specification and all the operations contained therein.

    Dominic Salemno
    Escalation Engineer
    Open Specifications

     

    • Proposed as answer by King Salemno Tuesday, January 18, 2011 6:23 AM
    • Marked as answer by King Salemno Wednesday, July 6, 2011 12:50 PM
    Tuesday, January 18, 2011 6:14 AM
    • Marked as answer by King Salemno Wednesday, July 6, 2011 12:50 PM
    Wednesday, July 6, 2011 12:48 PM

All replies

  • Hi, Alix,

      Thanks for your question.  One of our team member will look at the question and respond to you soon.

     


    Hongwei Sun -MSFT
    Thursday, January 6, 2011 4:09 PM
  • Alix,

    I am the engineer who has taken ownership of your issue. I am currently investigating this matter and will update you as things progress.

    Dominic Salemno
    Escalation Engineer
    Open Specifications

    Friday, January 7, 2011 2:02 PM
  • Alix,

     

    The FindItem Operation behavior that you described is working as it was designed. By default, only single calendar items and recurring master calendar items are returned. Thus one would have to expand the occurences themselves to find all instances. Review the FindItem Operation note found on this MSDN Page: http://msdn.microsoft.com/en-us/library/aa566107.aspx:

     

    The FindItem operation can return results in a CalendarView element. The CalendarView element returns single calendar items and all occurrences. If a CalendarView is not used, single calendar items and recurring master calendar items are returned. The occurrences must be expanded from the recurring master if a CalendarView is not used.

     

    Upon review of the CalendarView element in question on the CalendarView’s MSDN Page reveals the following remarks:

    If the CalendarView element is specified in a FindItem request, the Web service returns a list of single calendar items and occurrences of recurring calendar items within the range specified by StartDate and EndDate.

    If the CalendarView element is not specified in a FindItem request, the Web service returns a list of single calendar items and recurring master calendar items. Calendar occurrences of a recurring calendar item are not expanded.

    The schema that describes this element is located in the EWS virtual directory of the computer that is running Microsoft Exchange Server 2007 that has the Client Access server role installed.

    To solve your issue, you must present the CalendarView element in the FindItem request to have all occurrences of a recurring calendar item returned in the specified date range.

     

    I hope this information assists you Alix.

     

    Dominic Salemno
    Escalation Engineer

    Open Specifications
    • Proposed as answer by King Salemno Friday, January 7, 2011 6:37 PM
    • Marked as answer by Alix Dong Sunday, January 9, 2011 2:23 PM
    Friday, January 7, 2011 6:35 PM
  • My name is N.Shirato.

    Sorry, I'm Japanese and not good at English.

    I have more question.

    How else to get itemIds of recurring calendar items not ?

    I want to get itemIds of recurring calendar items related to a recurring mastar item.

    Thanks a lot.

    Friday, January 14, 2011 6:13 AM
  • Hi N.Shirato,

    Thanks for your question about itemIds.  One of our engineers with respond soon.

    Best regards,
    Tom Jebo
    Escalation Engineer
    Microsoft Open Specifications

    Friday, January 14, 2011 3:11 PM
  • N.Shirato,

    I am the engineer who has taken ownership of your question. I am currently investigating this and will update you as things progress.

    Dominic Salemno
    Escalation Engineer
    Open Specifications

    Friday, January 14, 2011 5:50 PM
  • N.Shirato,

    You should review the [MS-OXWSTASK] Specification Documentation and the GetItem Operation in Section 3.1.4.4. The document itself discusses the Tasks Web Service Protocol Specification and all the operations contained therein.

    Dominic Salemno
    Escalation Engineer
    Open Specifications

     

    • Proposed as answer by King Salemno Tuesday, January 18, 2011 6:23 AM
    • Marked as answer by King Salemno Wednesday, July 6, 2011 12:50 PM
    Tuesday, January 18, 2011 6:14 AM
  • Dominic,

     

    Thank you for your update.

    I know "GetItem" and use it to get "not recurring" calendar items, but couldn't find a way to get "recurring" calendar items.

    However, I contacted the Microsoft user support and was able to resolve it.

    That way seems to be not on the document that you told me.

    If not, would you please tell me where it ?

     

    Thanks a lot !

    I'm sorry my english is confusing.

     

    N.Shirato 

    Thursday, January 20, 2011 12:51 AM
    • Marked as answer by King Salemno Wednesday, July 6, 2011 12:50 PM
    Wednesday, July 6, 2011 12:48 PM