2015-11-02 84 views
-1

enter image description hereenter image description here当我下面的代码铸造,然后我得到一个错误无法投类型的COM对象“系统.__ ComObject”

代码:

string subject = ((Microsoft.Office.Interop.Outlook.MailItem)myInbox.Items[temp]) 
    .Subject.ToString(); 

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)).

+0

错误信息的其余部分是什么? – DavidG

+0

“没有这样的接口”我想 –

+0

现在你可以看到完整的错误信息 –

回答

2

您需要检查项目类型第一。 Outlook文件夹可能包含各种类型的项目:

Object selObject = this.Application.ActiveExplorer().Selection[1]; 
     if (selObject is Outlook.MailItem) 
     { 
      Outlook.MailItem mailItem = 
       (selObject as Outlook.MailItem); 
      itemMessage = "The item is an e-mail message." + 
       " The subject is " + mailItem.Subject + "."; 
      mailItem.Display(false); 
     } 
     else if (selObject is Outlook.ContactItem) 
     { 
      Outlook.ContactItem contactItem = 
       (selObject as Outlook.ContactItem); 
      itemMessage = "The item is a contact." + 
       " The full name is " + contactItem.Subject + "."; 
      contactItem.Display(false); 
     } 
     else if (selObject is Outlook.AppointmentItem) 
     { 
      Outlook.AppointmentItem apptItem = 
       (selObject as Outlook.AppointmentItem); 
      itemMessage = "The item is an appointment." + 
       " The subject is " + apptItem.Subject + "."; 
     } 
     else if (selObject is Outlook.TaskItem) 
     { 
      Outlook.TaskItem taskItem = 
       (selObject as Outlook.TaskItem); 
      itemMessage = "The item is a task. The body is " 
       + taskItem.Body + "."; 
     } 
     else if (selObject is Outlook.MeetingItem) 
     { 
      Outlook.MeetingItem meetingItem = 
       (selObject as Outlook.MeetingItem); 
      itemMessage = "The item is a meeting item. " + 
       "The subject is " + meetingItem.Subject + "."; 
     } 

请参阅How to: Programmatically Determine the Current Outlook Item了解更多信息。

+0

我有请求在我的收件箱中阅读收据类型Outlook邮件,我想从c#中读取特定邮件 –

0
string subject = myInbox.Items[temp]) 
    .Subject.ToString(); 

没有必要投弗里斯特检查myinbox对象具有学科性质的不串,那么你需要投它,如果它是字符串,那么甲就不需要投它。

相关问题