C# 为什么公用文件夹上的TotalCount属性总是返回0项?

C# 为什么公用文件夹上的TotalCount属性总是返回0项?,c#,exchange-server,exchangewebservices,C#,Exchange Server,Exchangewebservices,使用Exchange 2013 SP1和Exchange Web Services managed API 2.2尝试获取存储在公用文件夹中的联系人文件夹中的联系人列表我想将ItemView的大小限制在此联系人文件夹中的联系人总数,但当我尝试返回该属性(contactfolder.TotalCount)时,它总是返回0。如果我使用邮箱下的联系人文件夹尝试此操作,则返回的值不是0。我可以通过将ItemView的构造函数的值指定为特定的数字或使用int.MaxValue来解决这个问题,但我更愿意使用

使用Exchange 2013 SP1和Exchange Web Services managed 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;
    } 
private FindItemsResults ExchangeContacts()
{
//设置exchange服务器连接。
ExchangeService服务=新的ExchangeService(ExchangeVersion.Exchange2013\u SP1);
服务。自动发现URL(“someone@mydomain.com");
//设置筛选器以选择正确的联系人列表
SearchFilter=newsearchfilter.IsEqualTo(FolderSchema.DisplayName,“我的公共联系人”);
SearchFilter.SearchFilterCollection filterCollection=新建SearchFilter.SearchFilterCollection();
filterCollection.Add(过滤器);
//使用搜索筛选器获取文件夹ID。
文件夹父项=Folder.Bind(服务,WellKnownFolderName.PublicFoldersRoot);
FindFoldersResults=parent.FindFolders(过滤器,新FolderView(1));
FolderId fid=results.Single().Id;
//根据文件夹ID获取联系人文件夹。
ContactsFolder ContactsFolder=(ContactsFolder)结果。Single();
ItemView视图=新的ItemView(contactsfolder.TotalCount);
//设置需要在页面中显示的属性。
view.PropertySet=新属性集(BasePropertySet.IdOnly、ContactSchema.DisplayName、ContactSchema.CompanyName、ContactSchema.LastModifiedTime、ContactSchema.BusinessAddressCity、ContactSchema.BusinessAddressPostalCode、ContactSchema.BusinessAddressState、ContactSchema.BusinessAddressStreet、ContactSchema.HomeAddressCity、ContactSchema.HomeAddressPostalCode、ContactSchema.HomeAdd)ResState、ContactSchema.HomeAddressStreet、ContactSchema.ItemClass、ContactSchema.FileAs、ContactSchema.LastModifiedName);
//view.PropertySet=newpropertyset(BasePropertySet.IdOnly,ContactSchema.DisplayName);
//按所选属性之一对结果排序
//view.OrderBy.Add(ContactSchema.LastModifiedTime,Microsoft.Exchange.WebServices.Data.SortDirection.Descending);
FindItemsResults contactItems=contactsfolder.FindItems(视图);
归还物品;
} 

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

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

我猜您需要在搜索条件中指定属性筛选器。

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

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


我猜您需要在搜索条件中指定属性筛选器。

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

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