Outlook Interop:如何迭代文件夹中的所有项目

时间:2021-11-25 21:23:27

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:

我想搜索所有outlook项目的主体。我知道如何为四个PIM项(Notes / Tasks / Appointments / Contacts)执行此操作。但是除了将COM对象转换为特定的项类型(即ContactItem,AppointmentItem等)之外,所有这些代码都是相同的。这些PIM项是否有父类,因此我可以在循环中执行以下操作:


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.

Body是我想要获得的四个PIM项的共同属性。有这样的父项吗?如果不是,似乎API设计不佳?我想我可以抽象文件夹项,使它看起来像有一个父项...我也尝试使用反射做这个,但不能完全到达那里。

Any suggestsion?

2 个解决方案

#1


1  

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.

对于Outlook 2007,可以在Items集合中的对象列表位于此处。它包括没有正文的分发列表之类的东西,这使得你不想要的东西。

#2


0  

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,

虽然PIM项可能是从公共类派生的,但它不能通过com对象创建,但是,所有项都返回一个类属性,它是一个枚举它是什么类型的项。您可以在投射之前检查此属性以获取所需的四种类型的项目,

#1


1  

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.

对于Outlook 2007,可以在Items集合中的对象列表位于此处。它包括没有正文的分发列表之类的东西,这使得你不想要的东西。

#2


0  

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,

虽然PIM项可能是从公共类派生的,但它不能通过com对象创建,但是,所有项都返回一个类属性,它是一个枚举它是什么类型的项。您可以在投射之前检查此属性以获取所需的四种类型的项目,