Outlook 2010获取特定配置文件的联系人

时间:2015-04-02 12:21:34

标签: vb.net outlook outlook-2010

目前,我正在使用此代码获取所有联系人:

Dim outlookApplication = New Microsoft.Office.Interop.Outlook.Application()
Dim contacts As MAPIFolder = outlookApplication.GetNamespace("mapi").GetDefaultFolder(OlDefaultFolders.olFolderContacts)

For i As Integer = 1 To contacts.Items.Count

    Dim contact = DirectCast(contacts.Items(i), ContactItem)
    cboEmail.Items.Add(contact.Email1Address)
Next

但是当用户有多个配置文件出现错误消息时,我似乎遇到了问题:

System.InvalidCastException: Das COM-Objekt des Typs "Microsoft.Office.Interop.Outlook.ApplicationClass" kann nicht in den Schnittstellentyp "Microsoft.Office.Interop.Outlook._Application" umgewandelt werden. Dieser Vorgang konnte nicht durchgeführt werden, da der QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle mit der IID "{00063001-0000-0000-C000-000000000046}" aufgrund des folgenden Fehlers nicht durchgeführt werden konnte: Fehler beim Laden der Typbibliothek/DLL. (Ausnahme von HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).
   bei System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget, Boolean& pfNeedsRelease)
   bei Microsoft.Office.Interop.Outlook.ApplicationClass.get_Session()
   bei SKMailDatentransfer.frmMain.frmMain_Load(Object sender, EventArgs e)
   bei System.EventHandler.Invoke(Object sender, EventArgs e)
   bei System.Windows.Forms.Form.OnLoad(EventArgs e)
   bei System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   bei System.Windows.Forms.Control.CreateControl()
   bei System.Windows.Forms.Control.WmShowWindow(Message& m)
   bei System.Windows.Forms.Control.WndProc(Message& m)
   bei System.Windows.Forms.Form.WndProc(Message& m)
   bei System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

我应该提到的是,我开发了这个应用程序是一台带有Outlook 2013的PC,它可以在所有Outlook 2013 PC上正常运行,但在Outlook 2010上却很糟糕。 我在一台PC上解决了这个问题,但另一台仍无法正常工作。

2 个答案:

答案 0 :(得分:0)

Namespace类提供Stores属性,该属性返回Stores集合对象,该对象表示当前配置文件中的所有Store对象。 Store类提供GetDefaultFolder方法,该方法可用于获取Folder对象,该对象表示存储中的默认文件夹,并且是FolderType参数指定的类型。此方法类似于NameSpace对象的GetDefaultFolder方法。不同之处在于此方法获取与该帐户关联的传递存储上的默认文件夹,而NameSpace.GetDefaultFolder返回当前配置文件的默认存储上的默认文件夹。因此,通过这种方式,您可以获得特定于商店的联系人文件夹。

答案 1 :(得分:0)

具有多个配置文件的用户是否具有默认配置文件?如果没有,即如果Outlook必须询问在启动时使用哪个配置文件,则可能无法自动执行Outlook。

相关问题