These are chat archives for OfficeDev/ews-java-api

3rd
Dec 2015
Jose Carlos
@josecyn
Dec 03 2015 10:12
@DanielPio89 perhaps this function helps you to find it out:
    private static void searchCalendars (ExchangeService service, ArrayList<OutlookCalendar> output, ArrayList<Folder> folders, String sangria) {
        try {
            System.out.println(sangria+"The count of Subfolders: "+folders.size());
            int counter = 1;
            for (Folder folder : folders) {
                if (folder instanceof CalendarFolder) {
                    System.out.println(sangria+"#" + counter + " \"" + folder.getDisplayName() + "\" is a calendar folder!");
                    System.out.println(sangria+"-----> Found calendar named \"" + folder.getDisplayName() + "\" which has "+folder.getTotalCount()+" appointment(s) and id: " + folder.getId() + "\n");
                    output.add(new OutlookCalendar(folder.getId().getUniqueId(), folder.getDisplayName()));
                    FindFoldersResults next = service.findFolders(folder.getId(), new FolderView(Integer.MAX_VALUE));
                    searchCalendars (service, output, next.getFolders(), sangria+"\t");
                }
                else {
                    if (folder.getChildFolderCount() > 0) {
                        System.out.println(sangria+"#" + counter + " \"" +folder.getDisplayName() + "\" is not a calendar folder but it has "+folder.getChildFolderCount()+" subfolders. We resume the search inside this folder... ");
                        try {
                            FindFoldersResults result = service.findFolders(folder.getId(), new FolderView(Integer.MAX_VALUE));
                            searchCalendars (service, output, result.getFolders(), sangria+"\t");
                        }
                        catch (ServiceResponseException e) {
                            System.err.println(sangria+"Exception occurred: "+e.getMessage() + "\n");
                        }
                    }
                    else {
                        System.out.println(sangria+"#" + counter + " \"" +folder.getDisplayName() + "\" has 0 subfolders. Search in this folder finished!\n");
                    }
                }
                counter++;
            }
        }
        catch (Exception e) {
            System.out.println("Error searching appointments");
            e.printStackTrace();
        }
    }
Jose Carlos
@josecyn
Dec 03 2015 12:04

@DanielPio89 and this is how you can call it:

searchCalendars(exchangeService, output, exchangeService.findFolders(WellKnownFolderName.Root, new FolderView(Integer.MAX_VALUE)).getFolders(), "");