Multiple calender in exchange web service

时光毁灭记忆、已成空白 提交于 2019-12-11 02:53:21

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/24123416/multiple-calender-in-exchange-web-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!