2

I have multiple calenders in my mailbox. I can retrieve only one calender that is main calender folder using ews api 2.0. Now I want the whole list of calenders and appointments and meetings in that.

For example, I have three calenders, and one is the main calender

  1. Calender(color-code:default)

  2. Jorgen(color-code:pink)

  3. Soren(color-code: yellow)

i can retrieve all the values of main "Calnder", using the below code

Folder inbox = Folder.Bind(service, WellKnownFolderName.Calendar);

view.PropertySet = new PropertySet(BasePropertySet.IdOnly);

// This results in a FindItem call to EWS.
FindItemsResults<Item> results = inbox.FindItems(view);
i = 1;
m = results.TotalCount;
if (results.Count() > 0)
{
    foreach (var item in results)
    {
        PropertySet props = new PropertySet(AppointmentSchema.MimeContent, 
            AppointmentSchema.ParentFolderId, AppointmentSchema.Id, 
            AppointmentSchema.Categories, AppointmentSchema.Location);

        // This results in a GetItem call to EWS.
        var email = Appointment.Bind(service, item.Id, props);


        string iCalFileName = @"C:\export\appointment" +i ".ics";


        // Save as .eml.
        using (FileStream fs = new FileStream(iCalFileName, FileMode.Create, FileAccess.Write))
        {
            fs.Write(email.MimeContent.Content, 0, email.MimeContent.Content.Length);
        }
        i++;

Now I want to get all the remaining calender schedules also, I am not able to get it.

gunr2171
  • 16,104
  • 25
  • 61
  • 88
Vikas Lalwani
  • 1,041
  • 18
  • 29

1 Answers1

2

To get all the Calendar folders that are located in your own Mailbox (not including those in your personal archive if you have one) you can do a FindFolders with a Deep Traversal and filter on folders with a Folder Class of IPF.Appointment eg something like

            ExtendedPropertyDefinition PR_Folder_Path = new ExtendedPropertyDefinition(26293, MapiPropertyType.String);
        PropertySet psPropSet = new PropertySet(BasePropertySet.FirstClassProperties);
        psPropSet.Add(PR_Folder_Path);
        FolderId rfRootFolderid = new FolderId(WellKnownFolderName.Root, mbMailboxname);
        FolderView fvFolderView = new FolderView(1000);
        fvFolderView.Traversal = FolderTraversal.Deep;
        fvFolderView.PropertySet = psPropSet;
        SearchFilter sfSearchFilter = new SearchFilter.IsEqualTo(FolderSchema.FolderClass, "IPF.Appointment");
        FindFoldersResults ffoldres = service.FindFolders(rfRootFolderid, sfSearchFilter, fvFolderView);
        if (ffoldres.Folders.Count > 0) {
            foreach (Folder fld in ffoldres.Folders) {
                Console.WriteLine(fld.DisplayName);
            }
        }

For Shared Calendars you need to use something like EWS - Access All Shared Calendars

Cheers Glen

Community
  • 1
  • 1
Glen Scales
  • 20,495
  • 1
  • 20
  • 23