我正在开发一个 WPF-C# 应用程序并使用 Redemption 获取 MS Outlook 2010 联系人项目。如果我的 Outlook 只有一个 SMTP 帐户,它工作正常。但是,如果我配置另一个帐户是交换服务器帐户,那么我不会从同一代码中获得任何联系项目。以下是我的代码:
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());
}
当我删除我的交换服务器帐户时,它工作正常,如果我在 Outlook 中添加交换服务器帐户,那么此代码也不例外,但不提供任何联系项目。任何人都可以建议我这里可能是什么问题。提前致谢。
-苏里亚