Kei*_*ton 1 c# exchange-server exchangewebservices
使用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;
}
Run Code Online (Sandbox Code Playgroud)
我重新创建了您的公用文件夹(紧接在公用文件夹根目录下),添加了一个联系人,并运行了您的代码并获得了一个contactItems.TotalCount值为1(如预期的那样).但是,在与Exchange产品团队讨论后,我了解到,如果FindFolder请求被路由到没有公用文件夹内容的公用文件夹邮箱,则FindFolder可以返回不正确的值.因此,TotalCount可以返回不正确的值,并且不支持公用文件夹.我们将更新文档以反映此问题.
归档时间: |
|
查看次数: |
1313 次 |
最近记录: |