Outlook Interop:如何迭代文件夹中的所有项目
我想搜索所有 Outlook 项目的正文。 我知道如何对四个 PIM 项目(注释/任务/约会/联系人)执行此操作。 但除了将 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 是我想要获取的四个 PIM 项目的公共属性。 有这样的父项吗? 如果不是的话,API 设计似乎很糟糕? 我想我可以抽象文件夹项目,使其看起来像有一个父项目...我也尝试使用反射来做到这一点,但无法完全实现。
有什么建议吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看文档,我没有看到您想要的课程。
对于 Outlook 2007,项目集合中的对象列表位于此处< /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.
虽然 PIM 项可能派生自公共类,但它不能通过 com 对象创建,但是,所有 项目还返回class 属性,它是项目类型的枚举。 您可以在施放之前检查此属性是否有您想要的四种类型的物品,
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,