Initial start of Exchange Web Services synchronization at a specified time

We synchronize the Exchange web server with our application. To identify changes to the EWS we use; service.SyncFolderItems(), for example, explain in MSDN . But, performing the initial synchronization, he accepts all the events on the calendar, very old. To avoid aging, we need to use a period of time or Synchronize start from time when requesting changes from the method SyncFolderItems().

1) Can the SyncFolderItems () method accept a user-specified period of time when receiving events from EWS? And How?
2) If not, any workaround?

+4
source share
2 answers

There is a way to avoid old calendar events using the service.SyncFolderItems () method.

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

This Ignore option will accept a list of event identifiers. and ignore them when synchronizing. To do this, first we need to get the old event identifiers, Exchange will only accept a two-year 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 a list of product identifiers;

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

Create a calendar viewer;

CalendarView cView = new CalendarView(startDate, endDate);

Get an appointment,

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

Or you can use this, but the previous code has some optimization. (Google)

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

Add event IDs to the list,

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

        }

Finally, in your method, SyncFolderItems will look like this:

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

Hope this helps any of you.

+3
source

SyncFolderItems . , . . , .

, : 1) ItemId. . 2) FindItems , GetItem (Bind), , , , , . , , - , . . GetItem (Load), , , .

+1

Source: https://habr.com/ru/post/1538695/


All Articles