开发者

Error getting the content of an outlook 2007 message

I'm currently making a program that needs to analyze the mail message in outlook 2007 and outlook 2010.

On machines that have the office suite installed, it works no problem. If they only have outlook, it doesn't seem to be able to get the mail message and when I try to get the content of the document, it gives me the following error:

"Unable to cast COM object of type 
'Microsoft.Office.Interop.Word.DocumentClass' to interface type
'Microsoft.Office.Interop.Word._Document'. This operation failed because the 
QueryInterface call on th开发者_Python百科e COM component for the interface with IID '{0002096B-0000-
0000-C000-000000000046}' failed due to the following error: No such interface supported    
(Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."

This is the code I'm using to get the message:

Office.Word.Document document = inspector.WordEditor as Office.Word.Document;
string body = document.Content.Text;


To my knowledge, you should be casting it to a MailItem not a word document if you're going after the message. Off the MailItem object is a property called Body (and an associated BodyFormat).

Also, @StackOverflowException is correct, always check if the item is not null before you begin to manipulate it. This will tell you if it is or isn't the type you think it is.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜