Outlook 2016 Visual Studio 2015:无法访问HTMLBody属性 [英] Outlook 2016 Visual Studio 2015: unable to access HTMLBody property

查看:84
本文介绍了Outlook 2016 Visual Studio 2015:无法访问HTMLBody属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Windows 7 x64,我正在创建您的第一个AddIn演练,并且无法访问Inspectors.NewInspector事件中的mailItem.HTMLBody属性。   mailItem.Body工作正常。


查看源代码显示HTML标记。但是,当我在立即窗口中检查变量 mailItem
以查看其 HTMLBody 属性时,我收到错误CS1061:


'MailItem'不包含'HTMLBody'的定义,并且没有扩展方法'HTMLBody'接受
a可以找到类型'MailItem'的第一个参数(你是否缺少using指令或程序集参考?)



是否需要使用指令或程序集引用才能够检查这个属性?  





解决方案

你好lloydmalvern,


>>我正在关注创建您的第一个AddIn演练,并且无法访问Inspectors.NewInspector事件中的mailItem.HTMLBody属性。  mailItem.Body工作正常,


这里我在我的代码中测试了mailItem.HTMLBody和mailItem.Body,两者都正常工作,没有错误。我在您正在使用的相同环境中检查此代码。所以我没有重现你的问题。

我在这里发布我的代码。它可以帮助您解决问题。

使用System; 
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;
使用System.Xml.Linq;
使用Outlook = Microsoft.Office.Interop.Outlook;
使用Office = Microsoft.Office.Core;
使用System.IO;

名称空间OutlookAddIn4
{
公共部分类ThisAddIn
{
Outlook.Inspectors检查员;
private void ThisAddIn_Startup(object sender,System.EventArgs e)
{
inspectors = this.Application.Inspectors;
inspectors.NewInspector + =
new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);

}
void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
if(mailItem!= null)
{
if(mailItem.EntryID == null)
{
string stringHtmlBodyfromFile = File.ReadAllText(@" C: \Users\Administrator\Desktop\OutlookAddIn4\OutlookAddIn4\my.html");
mailItem.Subject ="此文本是使用代码添加的;
//mailItem.Body = stringHtmlBodyfromFile;
mailItem.HTMLBody = stringHtmlBodyfromFile;
}

}
}
private void ThisAddIn_Shutdown(object sender,System.EventArgs e)
{
//注意:Outlook no更长时间引发这一事件。如果您在Outlook关闭时必须运行
//代码,请参阅http://go.microsoft.com/fwlink/?LinkId=506785
}

#region VSTO生成代码

///< summary>
/// Designer支持的必需方法 - 不要使用代码编辑器修改
///此方法的内容。
///< / summary>
private void InternalStartup()
{
this.Startup + = new System.EventHandler(ThisAddIn_Startup);
this.Shutdown + = new System.EventHandler(ThisAddIn_Shutdown);
}

#endregion
}
}

如果您的代码仍有错误,请提供您的代码缩小此问题。


问候


Edward         &NBSP;&NBSP;

Using Windows 7 x64, I am following the create your first AddIn walkthrough, and am unable to access the mailItem.HTMLBody property in the Inspectors.NewInspector event.  mailItem.Body works fine, however.

View Source shows the HTML markup. But when I  inspect variable mailItem in the Immediate window to look at its HTMLBody property, I get error CS1061:

'MailItem' does not contain a definition for 'HTMLBody' and no extension method 'HTMLBody' accepting a first argument of type 'MailItem' could be found (are you missing a using directive or an assembly reference?)

Is there a using directive, or assembly reference, required in order to be able to examine this property?  


解决方案

Hi lloydmalvern,

>> I am following the create your first AddIn walkthrough, and am unable to access the mailItem.HTMLBody property in the Inspectors.NewInspector event.  mailItem.Body works fine,

Here I tested both mailItem.HTMLBody and mailItem.Body in my code and both are working correctly and there is no error. I have check this code on same environment you are using. So I am failed to reproduce your issue.
Here I am posting my code below. It might help you to solve your issue.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using System.IO;

namespace OutlookAddIn4
{
    public partial class ThisAddIn
    {
        Outlook.Inspectors inspectors;
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            inspectors = this.Application.Inspectors;
            inspectors.NewInspector +=
            new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);

        }
        void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
        {
            Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
            if (mailItem != null)
            {
                if (mailItem.EntryID == null)
                {
                    string stringHtmlBodyfromFile = File.ReadAllText(@"C:\Users\Administrator\Desktop\OutlookAddIn4\OutlookAddIn4\my.html");
                    mailItem.Subject = "This text was added by using code";
                    //mailItem.Body = stringHtmlBodyfromFile;
                    mailItem.HTMLBody= stringHtmlBodyfromFile;
                }

            }
        }
        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
            // Note: Outlook no longer raises this event. If you have code that 
            //    must run when Outlook shuts down, see http://go.microsoft.com/fwlink/?LinkId=506785
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }

        #endregion
    }
}

If your code still have error then kindly provide your code to narrow down this issue.

Regards

Edward          


这篇关于Outlook 2016 Visual Studio 2015:无法访问HTMLBody属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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