如何将System.Comobject类型转换为Microsoft.Office.Interop.Outlook._MailItem [英] How to cast System.Comobject type to Microsoft.Office.Interop.Outlook._MailItem
问题描述
Hi,
Outlook._NameSpace oNs = null;
Outlook.MAPIFolder oSents = null;
Outlook.Items oItems = null;
Outlook._MailItem oMICopy;
ns = olApp.GetNamespace("MAPI");
oSents = oNs .GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
oItems = oSents.Items;
var copy=oItems.Cast<Outlook._MailItem>();
oMICopy= copy.Where(x=>x.Recipients[0].Address.ToLower().ToString().Contains("Alex")).Select(y=>y).FirstOrDefault();
抛出异常无法将'System .__ ComObject'类型的COM对象强制转换为接口类型'Microsoft.Office.Interop .Outlook._MailItem'。此操作失败,因为IID为{00063034-0000-0000-C000-000000000046}的接口的COM组件上的QueryInterface调用由于以下错误而失败:不支持此类接口(HRESULT异常) :0x80004002(E_NOINTERFACE))。
如何获取Outlook._MailItem oMICopy。
请帮忙!
谢谢,
Prasanna
its throwing exception "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))."
How to Get Outlook._MailItem oMICopy.
Please help!
Thanks,
Prasanna
推荐答案
Outlook.Item s oItem s = null;
- 你看到单词末尾的复数吗?它不是单个项目,而是某种项目 s 的集合。
因此,var copy = oItems.Cast< outlook._mailitem> ;();< /outlook._mailitem>
没有意义。
我不知道Outlook.Items
支持Linq所需的接口,可能需要通过集合明确循环。
Outlook.Items oItems = null;
- Do you see the plural-s at the end of the words? It is not a single item, but some kind of a collection of items.
Consequently,var copy=oItems.Cast<outlook._mailitem>();</outlook._mailitem>
does not make sense.
I do not know ifOutlook.Items
supports the interfaces required by Linq, it could be necessary to explicitely loop thru the collection.
这篇关于如何将System.Comobject类型转换为Microsoft.Office.Interop.Outlook._MailItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!