使用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;
}