我正在开发一个WPF-C#应用程序并使用Redemption获取MS Outlook 2010联系人项目。如果我的Outlook只有一个SMTP帐户,它工作正常。但是,如果我配置另一个帐户是Exchange服务器帐户,那么我不会从相同的代码中获得任何联系人项目。以下是我的代码:
Interop.Redemption.RDOItems folderItems = null;
Interop.Redemption.RDOFolder folderContacts = null;
Interop.Redemption.RDOFolder folderSuggestedContacts = null;
List<GMContactItem> allOutlookContacts = null;
object itemObj = null;
List<Interop.Redemption.RDOContactItem> contactItemsList = null;
try
{
folderContacts = (RDOFolder)RDOSessionItem.GetDefaultFolder(Interop.Redemption.rdoDefaultFolders.olFolderContacts);
contactItemsList = new List<RDOContactItem>();
folderItems = folderContacts.Items;
for (int i = 1; folderItems.Count >= i; i++)
{
itemObj = folderItems[i];
if (itemObj is Interop.Redemption.RDOContactItem)
contactItemsList.Add(itemObj as RDOContactItem);
else
Marshal.ReleaseComObject(itemObj);
}
Marshal.ReleaseComObject(folderItems);
folderItems = null;
// getting items from the Suggested Contacts folder in Outlook
folderSuggestedContacts = RDOSessionItem.GetDefaultFolder(
rdoDefaultFolders.olFolderSuggestedContacts);
if (folderSuggestedContacts != null)
{
folderItems = folderSuggestedContacts.Items;
for (int i = 1; folderItems.Count >= i; i++)
{
itemObj = folderItems[i];
if (itemObj is Interop.Redemption.RDOContactItem)
contactItemsList.Add(itemObj as Interop.Redemption.RDOContactItem);
else
Marshal.ReleaseComObject(itemObj);
}
}
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
}
当我删除我的Exchange服务器帐户时,它工作正常,如果我在Outlook中添加Exchange服务器帐户,那么此代码没有例外,但不提供任何联系人项目。谁能告诉我这可能是什么问题。提前致谢。
-Surya
答案 0 :(得分:0)
你在看GAL条目吗?这些地址条目存在于GAL(基于AD)中,而不存在于Exchange邮箱的“联系人”文件夹中。
如果需要打开(非默认)PST存储的“联系人”文件夹,请调用RDOStore.GetDefaultFolder(olFolderContacts)而不是RDOSession.GetDefaultFolder(从默认存储中返回文件夹)。
可以使用RDOSession.Stores集合打开辅助PST存储。