多个日历在交换Web服务

时间:2014-06-09 15:21:21

标签: c# asp.net exchangewebservices

我的邮箱里有多个日历。我只能使用ews api 2.0检索一个作为主日历文件夹的日历。现在我想要整个日历,约会和会议清单。

例如,我有三个压延机,一个是主压光机

  1. 日历(颜色代码:默认值)

  2. 约根(颜色代码:粉红色)

  3. Soren(颜色代码:黄色)

  4. 我可以使用下面的代码

    检索主“Calnder”的所有值
    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++;
    

    现在我想得到所有剩余的日历时间表,我无法得到它。

1 个答案:

答案 0 :(得分:2)

要获取位于您自己的邮箱中的所有日历文件夹(不包括您个人存档中的那些文件夹),您可以使用深度遍历执行FindFolders并过滤文件夹类为IPF的文件夹。例如

之类的东西
            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);
            }
        }

对于共享日历,您需要使用EWS - Access All Shared Calendars

之类的内容

干杯 格伦