如何使用Java EWS api删除整个Exchange日历活动?

时间:2017-12-19 06:30:27

标签: java web-services exchange-server exchangewebservices

我已经编写了如下代码,它删除了具有当前日期的约会,但有一种方法可以一次删除整个日历约会。在此先感谢

epublic static HashSet<String> userEventEws(ExchangeService service)  {

    HashSet<String> listSubject = new HashSet<String>();

        Calendar yesterday = Calendar.getInstance();
        Calendar now = Calendar.getInstance();

        yesterday.add(Calendar.DATE, -1);
        now.add(Calendar.DATE, 1);
        Date startDate = yesterday.getTime();
        Date endDate = now.getTime();

        try {
            CalendarFolder calendarFolder = CalendarFolder.bind(service, WellKnownFolderName.Calendar, new PropertySet());
            CalendarView cView = new CalendarView(startDate,endDate);
            cView.setPropertySet(new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End));// we can set other properties 
            // as well depending upon our need.
            FindItemsResults appointments = calendarFolder.findAppointments(cView);

            List <Appointment>appList = appointments.getItems();
            for (Appointment appointment : appList) {
                listSubject.add(appointment.getSubject().trim());
                appointment.delete(DeleteMode.HardDelete);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }


    return listSubject;

}

1 个答案:

答案 0 :(得分:0)

通常,您有两个选项,您可以批量删除从FindItems返回的项目(查找约会将扩展定期约会,如果您要删除所有不想删除的项目,请删除主要和单个实例改为https://msdn.microsoft.com/en-us/library/office/dn626016(v=exchg.150).aspx#bk_deleteews

另一种选择是使用空文件夹操作,该操作应在2013年及以上https://msdn.microsoft.com/en-us/library/office/ff709484%28v=exchg.150%29.aspx