Exception occured when retrieving ContactItem in olFolderContacts

O

OctopusThu

I'm using the following code to try to retrieve ContactItems in Outlook:

Outlook.MAPIFolder defaultFolder = applicationObject.GetNamespace
("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);

foreach (Outlook.ContactItem item in defaultFolder.Items)
{
//codes......
}

However, there are also DistListItem in the same folder and the following
exception occured:

System.InvalidCastException: Unable to cast COM object of type
'System._ComObject' to interface type
'Microsoflt.Office.Interop.Outlook.ContactItem'. This operation failed
because the QueryInterface call on the COM component for the interface with
IID ......

Is there another way other than 'foreach' clause that I can get the
ContactItem or DistListItem in a Outlook folder?
 
K

Ken Slovak - [MVP - Outlook]

Your post was already answered in another group you posted in. Please do not
post in multiple groups and look for responses to your original post.
 

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