Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initial Exchange Web Services sync start on given time

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 ?

like image 285
shalin Avatar asked Apr 30 '14 08:04

shalin


1 Answers

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.

like image 120
shalin Avatar answered Nov 15 '22 05:11

shalin