2014-07-14 28 views
1

使用Exchange 2013 SP1和Exchange Web Services託管API 2.2嘗試獲取我存儲在公用文件夾中的聯繫人文件夾中的聯繫人列表。 我想將ItemView的大小限制爲我在此聯繫人文件夾中具有的聯繫人總數,但是當我嘗試返回該屬性(contactfolder.TotalCount)時,它始終返回0.如果我嘗試使用我的郵箱下的聯繫人文件夾返回值不爲0。我可以通過爲ItemView的構造函數指定值作爲特定數字或使用int.MaxValue來解決此問題,但我寧願使用聯繫人列表中的項目總數。任何援助非常感謝!下面是相關的代碼:爲什麼公用文件夾的TotalCount屬性總是返回0個項目?

private FindItemsResults<Microsoft.Exchange.WebServices.Data.Item> ExchangeContacts() 
    { 
     // Setup the exchange server connection. 
     ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1); 
     service.AutodiscoverUrl("[email protected]"); 

     // 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; 
    } 

回答

5

我重新創建了公用文件夾(立即在公共文件夾根目錄下),向其中添加了一個聯繫人,並運行了代碼並獲得了contactItems.TotalCount值1(如預期的那樣)。但是,在與Exchange產品團隊討論此事之後,我瞭解到如果FindFolder請求被路由到沒有公用文件夾內容的公用文件夾郵箱,則FindFolder可能返回不正確的值。所以TotalCount可以返回一個不正確的值,並且不支持公共文件夾。我們將更新文檔以反映此問題。

2

FindFolder operation (Exchange 2013)

使用用於BaseShape默認值,則響應返回 文件夾名稱,文件夾ID,子文件夾的數量,的 數在文件夾中找到的子文件夾以及未讀項目的數量。

< ...>

FindFolder響應與AllProperties一個請求響應 形狀將不會返回TOTALCOUNT和 公用文件夾搜索UnreadCount元素。

猜你需要在搜索條件中指定一個屬性過濾器。

相關問題