I'm currently trying to get just the contacts from an Items collection retrieved from Outlook. The problem is that my cast to ContactItem sometimes breaks because there are non-contact items in the list (like distribution lists). Because these are COM objects, I need to check if the property MessageClass equals IPM.Contact. I'm not familiar with COM objects, so I don't know how to do this. I've tried using the following:

if(comObject.GetType().GetProperty(MessageClass).GetValue(comObject).Equals("IPM.Contact"))
{
    contactitems.add((ContactItem)comObject)
}

However, this fails because it cannot find the property on the comobject.

有帮助吗?

解决方案

I checked MSDN, and they suggest at http://msdn.microsoft.com/en-us/library/ms268994.aspx to use object is ContactItem to check if it's a ContactItem. I've tried this, and it works.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top