Question

We are doing Exchange web server synchronization with our application. To identify EWS changes we use; service.SyncFolderItems() method, like explain on MSDN. But, while doing initial sync it takes all the events in calendar, very older ones too. To avoid getting older events we need to use time period or Sync Start From time while requesting changes from SyncFolderItems() method.

1) Can SyncFolderItems() method accept user given time period when getting events from EWS ? & How ?
2) If not, Any workaround ?

Was it helpful?

Solution

There is a way to avoid older events in calendar using service.SyncFolderItems() method.

<SyncFolderItems>
 <ItemShape/>
 <SyncFolderId/>
 <SyncState/>
 <Ignore/>
 <MaxChangesReturned/>   <SyncScope/>
</SyncFolderItems>

That Ignore parameter will accept List of event Ids. and ignore them while syncing. To do that , First we need to retrieve older event IDs, Exchange will only accept two years old event

        DateTime startDate = DateTime.Now.AddYears(-2); //start from two years earlier
        DateTime endDate = DateTime.Now.AddMonths(-1); // End One Month before,
//you can use Convert.ToDateTime("01/01/2013"); what ever date you wanted.

Create Item id List;

List<ItemId> itmid = new List<ItemId>();

Create Calendar View object;

CalendarView cView = new CalendarView(startDate, endDate);

Retrieve Appointments;

 // Retrieve a collection of appointments by using the calendar view.
        FindItemsResults<Item> appointments = service.FindItems(WellKnownFolderName.Calendar, cView);

Or you can use this, But previous code have some optimization. (Google)

FindItemsResults<Appointment> appointments = service.FindAppointments(WellKnownFolderName.Calendar, cView);

Add retrieve event ids into list,

foreach (var item in appointments)
        {
            itmid.Add(item.Id);

        }

Finally, in your SyncFolderItems method will looks like this;

service.SyncFolderItems(new FolderId(WellKnownFolderName.Calendar), PropertySet.IdOnly, itmid, 10, SyncFolderItemsScope.NormalItems, sSyncState);

Hope this will help any of you.

OTHER TIPS

Currently, SyncFolderItems only supports synchronizing the entire mailbox. It doesn't support synchronizing starting from a specific time period. This type of request has been shared with the product planners. Hopefully we'll see this type of functionality.

In terms of workarounds, you could: 1) Sync all of the events with only the ItemId. Throw away items don't need. 2) Perform a FindItems with your intended time period, use GetItem (Bind) to get the events, and then use notifications to learn when a new item arrives, or when an item is updated. What you won't get with this is what has changed. For new items, this isn't an issue. But for updated items, you'll have to perform a GetItem (Load) and then diff the updated and old items to see what has changed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top