Visual studio 2010 如何使用EWS检索Outlook联系人?

Visual studio 2010 如何使用EWS检索Outlook联系人?,visual-studio-2010,outlook,exchangewebservices,Visual Studio 2010,Outlook,Exchangewebservices,我希望outlook联系人显示在网格视图中。Exchange Web服务如何在这方面帮助我?首先,从NuGet获取EWS: Install-Package EWS-Api-2.0 接下来,建立与Exchange服务器的连接: String用户名=”account@contoso.com"; 字符串password=“mypassword”; ExchangeService ews=新的ExchangeService(); ews.Credentials=新的WebCredentials(用户名

我希望outlook联系人显示在网格视图中。Exchange Web服务如何在这方面帮助我?

首先,从NuGet获取EWS:

Install-Package EWS-Api-2.0
接下来,建立与Exchange服务器的连接:

String用户名=”account@contoso.com";
字符串password=“mypassword”;
ExchangeService ews=新的ExchangeService();
ews.Credentials=新的WebCredentials(用户名、密码);
//如果您有Exchange URI,那么提供它会更快。然而,
//如果你没有,你可以自动获得它。用户可选择以下任一选项:
ews.Url=新的Url(“https://exchange.server.com/ews/exchange.asmx"); // 你自己的网址
ews.AutodiscoverUrl(用户名,x=>{
//您可以在此处验证“x”。出于测试目的,允许所有URL
返回true;
});
接下来,我们抓取联系人:

//联系人位于“联系人”文件夹中
Folder Contacts文件夹=Folder.Bind(ews,WellKnownFolderName.Contacts);
//一次抓取100个条目
ItemView ItemView=新项目视图(100);//一次列出100个条目
//检索前100个
FinditemsResults items=contactsFolder.FindItems(itemView);
//对条目进行迭代
foreach(items.OfType()中的var contact)
{
Console.WriteLine(contact.Id.UniqueId);
Console.WriteLine(“\t{0,-20}:{1}”,“昵称”,contact.昵称);
Console.WriteLine(“\t{0,-20}:{1}”,“DisplayName”,contact.DisplayName);
Console.WriteLine(“\t{0,-20}:{1}”,“电子邮件地址”,contact.EmailAddresses[0]);
Console.WriteLine();
}

从那里,您可以将上面的内容放在一个循环中,并检查
items.moreavable
以查看是否需要再获取100个条目。确保在后续调用中也向
ItemView
提供
offset
参数。

无代码,无帮助,就这么简单!