16

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.

Alfred Myers
  • 6,384
  • 1
  • 40
  • 68
tvanfosson
  • 524,688
  • 99
  • 697
  • 795

4 Answers4

4

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.

MJB
  • 9,352
  • 6
  • 34
  • 49
  • care to add a code sample or include a reference? I was able to get things working, but only by filtering the responses. I was using someone else's code as a starting point, which is why I started with the CalendarItemView (which sounds reasonable since I'm looking for calendar items), but I'd like to try doing it your way. – tvanfosson Apr 25 '11 at 12:03
  • 1
    I'd like to but our code is frankly a bit of a mess. We started with a Thread jamming stuff in 50 items at a time (and some complicated/avoid race condition stuff I'm not fond of). That performed FindItem (idOnly) followed by getItems. Then we found indeed that in normal IndexedPageView we got only the master items. Allow me to recommend THE HOLY GRAIL - it's slightly outdated (2007 web services), but it is comprehensive, clear, with lots of examples...... – MJB Apr 25 '11 at 16:48
  • It's a book called Inside Microsoft Exchange Server 2007 Web Services by Microsoft Press. And it discusses so MANY weird corner cases of EWS. Every development team should have a copy. Inside Microsoft® Exchange Server 2007 Web Services by David Sterling; Ben Spain; Michael Mainer; Mark Taylor; Huw Upshall -------------------------------------------------------------------------------- Publisher: Microsoft Press Pub Date: November 28, 2007 Print ISBN-10: 0-7356-2392-9 Print ISBN-13: 978-0-7356-2392-7 – MJB Apr 25 '11 at 16:50
1

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.

Chris D
  • 134
  • 1
  • 10
0

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

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);
eL-Prova
  • 1,084
  • 11
  • 27
  • IsRecurring will be false for masters owned by the organizer. See http://msdn.microsoft.com/en-us/library/office/bb204271(v=exchg.150).aspx – Antony Feb 07 '14 at 22:05