c# - 为什么公用文件夹的 TotalCount 属性总是返回 0 个项目?

标签 c# exchange-server exchangewebservices

使用 Exchange 2013 SP1 和 Exchange Web 服务托管 API 2.2 尝试获取我存储在公共(public)文件夹中的联系人文件夹中的联系人列表。 我想将 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;
    } 

最佳答案

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

关于c# - 为什么公用文件夹的 TotalCount 属性总是返回 0 个项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24741105/

相关文章:

java - 从 Java 与 Exchange 2003 对话

exchangewebservices - item.HasAttachments 为 true,但集合中没有附件

c# - 是否有一个属性可以避免 MSTest 中的级联单元测试失败?

java - 在 'for' 循环中递增 1 时格式化背后的技术原因?

c# - 从委托(delegate)中锁定静态对象不起作用

c# - 可以在 BEARER 授权 header 中嵌入用户名吗?

c# - Powershell 和 C# 中的交换

vb.net - 为什么在使用 SmtpDeliveryMethod.SpecifiedPickupDirectory 时,电子邮件上的密件抄送邮件 header 不起作用?

python - 如何通过 Office 365 REST API 检索 Internet(消息) header ?

c# - 获取日历的工作时间需要什么权限?