【问题标题】:Why does TotalCount property on public folder always return 0 items?为什么公用文件夹上的 TotalCount 属性总是返回 0 个项目?
【发布时间】:2014-07-24 18:24:24
【问题描述】:

使用 Exchange 2013 SP1 和 Exchange Web 服务托管 API 2.2 尝试获取我存储在公用文件夹中的联系人文件夹中的联系人列表。 我想将 ItemView 的大小限制为我在此联系人文件夹中的联系人总数,但是当我尝试返回该属性 (contactfolder.TotalCount) 时,它总是返回 0。如果我尝试使用我邮箱下的联系人文件夹返回 0 以外的值。我可以通过将 ItemView 的构造函数的值指定为特定数字或使用 int.MaxValue 来解决此问题,但我宁愿使用联系人列表中的项目总数。非常感谢任何帮助!以下是相关代码:

private FindItemsResults<Microsoft.Exchange.WebServices.Data.Item> ExchangeContacts()
    {
        // Setup the exchange server connection.
        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
        service.AutodiscoverUrl("someone@mydomain.com");

        // Set the filter to choose the correct contact list
        SearchFilter filter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, "My Public Contacts");
        SearchFilter.SearchFilterCollection filterCollection = new SearchFilter.SearchFilterCollection();
        filterCollection.Add(filter);           


        // Get the FolderId using the search filter.
        Folder parent = Folder.Bind(service, WellKnownFolderName.PublicFoldersRoot);
        FindFoldersResults results = parent.FindFolders(filter, new FolderView(1));
        FolderId fid = results.Single().Id;

        // Get the Contact folder based on the folderid.
        ContactsFolder contactsfolder = (ContactsFolder)results.Single();            
        ItemView view = new ItemView(contactsfolder.TotalCount);

        // Set the property that need to be shown in the page.
        view.PropertySet = new PropertySet(BasePropertySet.IdOnly, ContactSchema.DisplayName, ContactSchema.CompanyName, ContactSchema.LastModifiedTime, ContactSchema.BusinessAddressCity, ContactSchema.BusinessAddressPostalCode, ContactSchema.BusinessAddressState, ContactSchema.BusinessAddressStreet, ContactSchema.HomeAddressCity, ContactSchema.HomeAddressPostalCode, ContactSchema.HomeAddressState, ContactSchema.HomeAddressStreet, ContactSchema.ItemClass, ContactSchema.FileAs, ContactSchema.LastModifiedName);
        //view.PropertySet = new PropertySet(BasePropertySet.IdOnly, ContactSchema.DisplayName);

        // Order the results by one of the selected properties
        //view.OrderBy.Add(ContactSchema.LastModifiedTime, Microsoft.Exchange.WebServices.Data.SortDirection.Descending);           

        FindItemsResults<Microsoft.Exchange.WebServices.Data.Item> contactItems = contactsfolder.FindItems(view);

        return contactItems;
    } 

【问题讨论】:

    标签: c# exchange-server exchangewebservices


    【解决方案1】:

    我重新创建了您的公用文件夹(直接在公用文件夹根目录下),向其中添加了一个联系人,然后运行您的代码并获得一个 contactItems.TotalCount 值为 1(如预期的那样)。但是,在与 Exchange 产品团队讨论此问题后,我了解到如果 FindFolder 请求被路由到没有公用文件夹内容的公用文件夹邮箱,FindFolder 可能会返回不正确的值。因此 TotalCount 可能返回不正确的值,并且不支持公用文件夹。我们将更新文档以反映此问题。

    【讨论】:

      【解决方案2】:

      FindFolder operation (Exchange 2013):

      使用 BaseShape 的默认值,响应返回 文件夹名称、文件夹 ID、子文件夹数量、 在文件夹中找到的子文件夹,以及未读项目的计数。

      <...>

      FindFolder 使用 AllProperties 响应响应请求 shape 不会返回 TotalCount 和 UnreadCount 元素 公用文件夹搜索。

      猜你需要在搜索条件中指定一个属性过滤器。

      【讨论】:

        猜你喜欢
        • 2021-01-24
        • 2016-09-16
        • 2020-05-25
        • 2013-02-26
        • 2013-06-25
        • 1970-01-01
        • 2011-06-16
        • 1970-01-01
        相关资源
        最近更新 更多