16
votes

I'm using a CalendarItemType view to retrieve calendar items. The only items I care about are those that I've created and I know that they are all weekly recurring items. I'm able to get each individual occurrence and, from any one of them the recurring master item, but I'd like to narrow the scope of my search to just those items that would match my pattern.

I've trying using the Restriction property on the FindItemType to specify a NotEqualTo restriction with a null constant for calenderRecurrenceId. This caused my request to time out. So far I've been unable to load the recurrences with the FindItemType at all and need to use a subsequent GetItemType call when I find an event that is an occurence in a recurring series.

Here's the code that I'm starting with. The code needs to work with both Exchange 2007 and Exchange 2010.

    var findItemRequest = new FindItemType();

    findItemRequest.ParentFolderIds = new DistinguishedFolderIdType[]
    {
        new DistinguishedFolderIdType()
    };

    ((DistinguishedFolderIdType)findItemequest.ParentFolderIds[0]).Id = DistinguishedFolderIdNameType.calendar;
    findItemRequest.Traversal = ItemQueryTraversalType.Shallow;

    var itemShapeDefinition = new ItemResponseShapeType(
    {
        BaseShape = DefaultShapeNamesType.AllProperties;
    }

    findItemRequest.Item = calenderView;
    findItemRequest.ItemShape = itemShapeDefinition;

    var findItemResponse = this.esb.FindItem( findItemRequest );

Also, if you know of any good source of examples (beyond the ones in MSDN), I'd welcome them. I'm picking up someone else's code in an emergency and trying to learn Exchange Web Services on the fly.

4
When I was learning EWS, I used EWSEditor's code as a reference.Avilo

4 Answers

4
votes

Maybe I'm misunderstanding you, in which case I apologize.

You do NOT use the CalendarView - you use the normal IndexedPageItemView if all you want is Master Recurring Calendar items.

You use the CalendarView to expand the recurrences to individual items. However the compromise with CalendarView is NO restrictions are permitted besides Start and End Date. None.

1
votes

You can search for a RecurrenceMaster by using the recurrence PidLid with an ExtendedPropertyDefinition. This works because, according to their documentation, "this property must not exist on single instance calendar items."

https://msdn.microsoft.com/en-us/library/cc842017.aspx

// https://msdn.microsoft.com/en-us/library/cc842017.aspx
ExtendedPropertyDefinition apptType = new ExtendedPropertyDefinition(
    DefaultExtendedPropertySet.Appointment,
    0x00008216, //PidLidAppointmentRecur
    MapiPropertyType.Binary);

var restriction = new SearchFilter.Exists(apptType);
var iView = new ItemView(10);
var found = folder.FindItems(restriction, iView);

I just confirmed this works, today, when revisiting some old code that works with Office365 EWS in the cloud.

0
votes

Found only property you need is RecurrenceStart property. Because EWS has limitations it is not possible to use all properties in restriction. This one working as expected.

Reference: Find master recurring appointments

-1
votes

You can create custom searchfilters. If you search from specific startdate OR isRecurring property you have most easy way...(SearchItems returns recurring masters)

List<SearchFilter> searchFilterCollection = new List<SearchFilter>();

        SearchFilter.IsGreaterThanOrEqualTo startDatumFilter = new SearchFilter.IsGreaterThanOrEqualTo(AppointmentSchema.Start, new DateTime(2012, 9, 16));
        SearchFilter.IsEqualTo masterRecurringFilter = new SearchFilter.IsEqualTo(AppointmentSchema.IsRecurring, true);

        searchFilterCollection.Add(startDatumFilter);
        searchFilterCollection.Add(masterRecurringFilter);

        SearchFilter finalFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchFilterCollection);

        ItemView itemView = new ItemView(100000);
        itemView.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, AppointmentSchema.AppointmentType);

        FindItemsResults<Item> items = _service.FindItems(WellKnownFolderName.Calendar, finalFilter, itemView);