确定Outlook项目的类型 [英] Determine type of Outlook item

查看:117
本文介绍了确定Outlook项目的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



循环浏览Outlook收件箱时,我想测试当前的Outlook项目是否为mailitem。如果是,那就开始吧;否则跳过并检查新条目。

这是我的代码看起来像



Hi all,

While looping through the Outlook inbox i want to test whether the current outlook item is mailitem or not. If it is, then work on it; else skip and check new entry.
This is what my code looks like

foreach (Outlook.MailItem mailitem in programobj.folder.Items)
{

    try
    {


        if (!(mailitem is Outlook.MailItem))
        {
          // skip...
            continue;
        }
       else
       {
         //work here
        }
  catch(exception e)
  {
    //some message or log
  }





它非常有效,直到它找到除mailitem之外的任何条目,如Calendar项目,注意项目等。对于这样的项目它给我异常和循环挂在那里

这是我得到的错误:



无法将System .__ ComObject类型的COM对象转换为接口类型Microsoft.Office.Interop.Outlook.MailItem。此操作失败,因为由于以下错误,IID为{00063034-0000-0000-C000-000000000046}的接口的COM组件上的QueryInterface调用失败:不支持此类接口(HRESULT异常:0x80004002(E_NOINTERFACE)) 。



请帮帮我。我无法修改代码。请给我解决方案,我可以测试给定的项目是否是mailitem与简单的if(条件)否则...



提前谢谢!!!



It works very well untill it finds any entry other than mailitem like Calendar item, note item, etc. For such items it gives me exception and loop hangs there itself
This is the Error i am getting:

Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.MailItem'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063034-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

Please help me with this. I cannot modify code much. Please give me solution where i can test whether the given item is mailitem or not with simple if(condition) else...

Thanks in advance!!!

推荐答案

您已经隐式地将 programobj.folder.Items 中的每个项目投射到 Outlook .MailItem 输入foreach循环标题( foreach(Outlook.MailItem mailitem in ...))。



试试这个:

You are already implicitly casting each item in programobj.folder.Items to the Outlook.MailItem type in the foreach loop header (foreach (Outlook.MailItem mailitem in...)).

Try this:
foreach (object item in programobj.folder.Items)
{
   try
   {
     if (item is Outlook.MailItem)
     {
       Outlook.MailItem mailitem = (Outlook.MailItem)item;
       // do something with mailitem
     }
   }
   catch(exception e)
   {
       //some message or log
   }





问候,



Thomas。



Regards,

Thomas.


这篇关于确定Outlook项目的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆