我想解决的问题: 获取所有联系人信息,如姓名和手机,并将其写入文件并保存在ISO。
这是我的代码:
private void btnSearch_Click(object sender, RoutedEventArgs e)
{
Contacts contacts = new Contacts();
contacts.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(contacts_SearchCompleted);
contacts.SearchAsync(displayName,FilterKind.DisplayName,null);
//search for all contacts
contacts.SearchAsync(string.Empty, FilterKind.None, null);
}
更新
如果PhoneNumber为Empty,则下面的代码抛出NullException错误。为什么呢?
如何获取result.PhoneNumbers.FirstOrDefault().ToString();
以外的所有可能电话号码
EmailAddresses的相同问题
使用此功能搜索手机中的所有联系人:
contacts.SearchAsync(searchterm, FilterKind.None, null);
void contacts_SearchCompleted(object sender, ContactsSearchEventArgs e)
{
int intTTL = e.Results.Count();
if (intTTL != 0)
{
MessageBox.Show(intTTL.ToString());
foreach (var result in e.Results)
{
string strTTL;
string strName = result.DisplayName;
string MobileNo = result.PhoneNumbers.FirstOrDefault().ToString();
strTTL = strName + "," + MobileNo;
MessageBox.Show(strTTL);
}
else
{
MessageBox.Show("You have not entered any contact info at all.");
}
}
答案 0 :(得分:0)
查看this article to see how to get the Contacts:
迭代:
void contacts_SearchCompleted(object sender, ContactsSearchEventArgs e)
{
foreach(var contact in e.Results)
{
// write to Isolated storage
}
}