views:

1463

answers:

2

I would like to search the bodies of all outlook items. I know how to do this for the four PIM items (Notes/Tasks/Appointments/Contacts). But the code is identical for all of them with the exception of casting the COM object to the specific item type (i.e., ContactItem, AppointmentItem, etc). Is there a parent class for these PIM items, so that I can do something like this in my loop:


using Outlook = Microsoft.Office.Interop.Outlook

List SearchFolderItems( Outlook.Folder folder )
{
   List results = new List();
   foreach( object folderItem in folder.Items )
   {
      //GenericPIMItem is what I am wishing for
      Outlook.GenericPIMItem item  = (Outlook.GenericPIMItem)folderItem;
      if( item.Body.ToLower().Contains( "secret sauce" ) )
      {
         results.Add( item.Name );
      }
   }
}


Body is a common property of the four PIM items I want to get at. Is there such a parent item? Seems poor API design if not? I suppose I could abstract the folder item, to make it look like there is a parent item... I also tried to do this using reflection, but couldn't quite get there.

Any suggestsion?

+1  A: 

Looking at the documentation, I don't see a class like you want.

For Outlook 2007, the list of objects that can be in an Items collection is here. It includes things like distribution lists that don't have a body, which makes what you want unlikely.

David Norman
A: 

While the PIM items might be derived from a common class, it is not creatable through the com object, but, all items also return a class property, which is an enumeration for what type of item it is. You could check this property for the four types of items you want before you cast,

cspirz