Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# “检索到”;“主题”;使用.ActiveInspector().CurrentItem时,合成电子邮件的数量有时为空_C#_Outlook_Vsto_Outlook Addin - Fatal编程技术网

C# “检索到”;“主题”;使用.ActiveInspector().CurrentItem时,合成电子邮件的数量有时为空

C# “检索到”;“主题”;使用.ActiveInspector().CurrentItem时,合成电子邮件的数量有时为空,c#,outlook,vsto,outlook-addin,C#,Outlook,Vsto,Outlook Addin,我们在编写VSTO Outlook加载项时遇到一个问题。在执行ItemSend时,获取已撰写电子邮件的主题效果良好,但在撰写电子邮件时(在ItemSend之前)尝试获取主题时,检索到的主题有时为空。它是一个预览功能,通过功能区上的按钮触发 设置一个断点,看起来ActiveInspector().CurrentItem没有提供正确的主题值 Ribbon_TabNewMailMessage.cs: private void PreviewButton_Click(object sende

我们在编写VSTO Outlook加载项时遇到一个问题。在执行ItemSend时,获取已撰写电子邮件的主题效果良好,但在撰写电子邮件时(在ItemSend之前)尝试获取主题时,检索到的主题有时为空。它是一个预览功能,通过功能区上的按钮触发

设置一个断点,看起来ActiveInspector().CurrentItem没有提供正确的主题值


Ribbon_TabNewMailMessage.cs:

    private void PreviewButton_Click(object sender, RibbonControlEventArgs e)
        {

            // pointing to ThisAddIn.cs (see code block below)
        if (Globals.ThisAddIn.Application.ActiveInspector() != null)
            {
                // Obviously sometimes not catching subject
                Outlook.MailItem mailItem = Globals.ThisAddIn.Application.ActiveInspector().CurrentItem;

                // BAD CASE: mailItem.Subject is sometimes NULL
                var aSubj = mailItem.Subject;


ThisAddIn.cs:

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {

            try
            {

                ...
                // Get the Application object
                Outlook.Application application = this.Application;

                // Subscribe to the ItemSend event, that it's triggered when an email is sent
                application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(ItemSend_BeforeSend);

                // new itemsend event
                void ItemSend_BeforeSend(object item, ref bool cancel)
                {

                   Outlook.MailItem mailItem = (Outlook.MailItem)item;

           // GOOD CASE: this one is working properly !!!   
           var bSubj = mailItem.Subject;


mailItem.Subject应具有来自邮件主题的值,但在不正确的情况下,它将返回NULL。

Subject
属性将在焦点离开主题编辑框之前不会更新

您可以尝试查找编辑框HWND并使用Windows API检索其文本(GetWindowText等)

如果您需要获得最新的更改,该方法会有所帮助。它将Microsoft Outlook项目保存到当前文件夹中,如果是新项目,则保存到该项目类型的Outlook默认文件夹中


您还可以将光标切换到窗口中的另一个字段,以将更改传播到Outlook对象模型。Outlook将缓存值,直到光标移动到另一个字段。在处理OOM时,这是一个已知问题。

执行邮件项目。在邮件项目之前保存。主题完成了该操作。太好了,非常感谢!!!谢谢你的描述@Eugene Astafiev。在VB.Net API中移动光标的任何方法。这是另一个问题的主题,请在此处发布。感谢您提出的解决方案,执行mailItem。在mailItem之前保存。主题立即完成了操作。