View Single Post
  #1  
Old November 9th 06, 05:56 AM posted to microsoft.public.outlook.program_forms
OctopusThu
external usenet poster
 
Posts: 25
Default Exception occured when retrieving ContactItem in olFolderContacts

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?


Ads