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?
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?