Outlook 2010 get contacts of a specitfic Profile

0

Currently I am getting all my Contacts with this code:

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

But I seem to have Problems when a user has more than one Profile thats the error Message:

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)

What I should had mentioned is that I developed this app an a PC with Outlook 2013 and it works fine on all Outlook 2013 PC but failes on Outlook 2010. I fixed the problem on one PC but the other one still wont work.

vb.net
outlook
outlook-2010
asked on Stack Overflow Apr 2, 2015 by RaverTiny • edited Apr 7, 2015 by RaverTiny

2 Answers

0

The Namespace class provides the Stores property which returns a Stores collection object that represents all the Store objects in the current profile. The Store class provides the GetDefaultFolder method which can be used to get a Folder object that represents the default folder in the store and that is of the type specified by the FolderType argument. This method is similar to the GetDefaultFolder method of the NameSpace object. The difference is that this method gets the default folder on the delivery store that is associated with the account, whereas NameSpace.GetDefaultFolder returns the default folder on the default store for the current profile. So, that way you can get a store-specific contacts folder.

answered on Stack Overflow Apr 2, 2015 by Eugene Astafiev
0

Does the user with multiple profiles have a default profile? If not, i.e. if Outlook has to ask which profile to use on startup, you may not be able to automate Outlook.

answered on Stack Overflow Apr 2, 2015 by Cain T. S. Random

User contributions licensed under CC BY-SA 3.0