Outlook plugin hangs when trying to access AddressEntry object

T

Tim Shirley

I'm attempting to access the entries in an Outlook user's contact list
from within an Outlook plugin in C# (using Visual Studio 2003 and
Outlook 2003). The following block of code works correctly, until it
gets to the last line (attempting to cast one of the items from the
contact list into an AddressEntry object) and then it hangs:

Outlook.NameSpace outlookNS = new
Outlook.ApplicationClass().GetNamespace("MAPI");
Outlook.Items coll =
outlookNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts).Items;
MessageBox.Show("Got collection. item count is " + coll.Count);
MessageBox.Show("First item uncast is " + coll.GetFirst());
MessageBox.Show("First item cast is " + ((Outlook.AddressEntry)
(coll.GetFirst())));

I've tried this on a couple of different machines using Outlook 2003,
but it hangs at the same spot on both. (The message box saying "First
item cast is ..." never appears.) Any ideas what's going on here?

Thanks!
 
D

Dmitry Streblechenko \(MVP\)

MAPIFolder.Items collection returns either Outlook.ContactItem or
Outlook.DistListItem objects, but never Outlook.AddressEntry object.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
D

Dmitry Streblechenko \(MVP\)

Clarification: MAPIFolder.Items collection returns either
Outlook.ContactItem or Outlook.DistListItem objects for the Contact
folders. For other folders it can be MailItem, TaskItem, etc.
As a rule of thumb, you should be checking the Class property (all Outlook
objects have that property) - for the contact items (ContactItem), it is 40.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top