C# VSTO outlook扫描打开的项目

C# VSTO outlook扫描打开的项目,c#,outlook,vsto,outlook-addin,C#,Outlook,Vsto,Outlook Addin,我的解决方案有点奇怪。 我想扫描一个特定的字串(这些特定的字串已经在一个XML数据文件中)来实现这一点,我想通过以下步骤来实现这一点 我将有一个菜单准则来更改外接程序的设置(现在不需要) 我会在酒吧里有一个新的按钮 然后假设用户正在阅读在阅读窗格中选择并打开的项目。当按下我的按钮时,我希望代码扫描主题和主体以与我的xml数据匹配,如果它存在,则显示一个消息框 我已经创建了菜单项和菜单栏按钮以及xml数据,现在我的问题是如何扫描当前正在读取的项 这是我在此addin.cs中的C#代码 us

我的解决方案有点奇怪。 我想扫描一个特定的字串(这些特定的字串已经在一个XML数据文件中)来实现这一点,我想通过以下步骤来实现这一点 我将有一个菜单准则来更改外接程序的设置(现在不需要) 我会在酒吧里有一个新的按钮

然后假设用户正在阅读在阅读窗格中选择并打开的项目。当按下我的按钮时,我希望代码扫描主题和主体以与我的xml数据匹配,如果它存在,则显示一个消息框

我已经创建了菜单项和菜单栏按钮以及xml数据,现在我的问题是如何扫描当前正在读取的项

这是我在此addin.cs中的C#代码

  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.Windows.Forms;

namespace Sql_openertake1
{
    public partial class ThisAddIn
    {
        private Office.CommandBar menuBar;
        private Office.CommandBarPopup newMenuBar;
        private Office.CommandBarButton buttonOne;
        Office.CommandBarButton PacktButtonA;
        Office.CommandBar PacktCustomToolBar;

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

         // Verify the PacktCustomToolBar exist and add to the application
if (PacktCustomToolBar == null)
{
// Adding the commandbar to Active explorer
Office.CommandBars PacktBars = this.Application.
ActiveExplorer().CommandBars;
// Adding PacktCustomToolBar to the commandbars
PacktCustomToolBar = PacktBars.Add("SQL Opener",Office.MsoBarPosition.msoBarTop, false, true);
}
// Adding button to the custom tool bar
Office.CommandBarButton MyButton1 = (Office.
CommandBarButton)PacktCustomToolBar.Controls.Add(1,
missing, missing, missing, missing);
// Set the button style
MyButton1.Style = Office.MsoButtonStyle.msoButtonCaption;
// Set the caption and tag string
MyButton1.Caption = "Open";
MyButton1.Tag = "MY BUTTON";
if (this.PacktButtonA == null)
{
// Adding the event handler for the button in the toolbar
this.PacktButtonA = MyButton1;
PacktButtonA.Click += new Office.
_CommandBarButtonEvents_ClickEventHandler(ButtonClick);
}
}
// Button event in the custom toolbar
private void ButtonClick(Office.CommandBarButton ButtonContrl,
ref bool CancelOption)
{
// Message box displayed on button click
MessageBox.Show(ButtonContrl.Caption + " Says Hello World!");
}

        private void AddMenuBar()
        {
            try
            {
                menuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar;
                newMenuBar = (Office.CommandBarPopup)menuBar.Controls.Add(
                    Office.MsoControlType.msoControlPopup, missing,
                    missing, missing, true);
                if (newMenuBar != null)
                {
                    newMenuBar.Caption = "SQL Opener";
                    buttonOne = (Office.CommandBarButton)newMenuBar.Controls.
                    Add(Office.MsoControlType.msoControlButton, missing,
                        missing, 1, true);
                    buttonOne.Style = Office.MsoButtonStyle.
                        msoButtonIconAndCaption;
                    buttonOne.Caption = "Settings";
                    buttonOne.FaceId = 0548;
                    buttonOne.Tag = "c123";
                    buttonOne.Click += new Office._CommandBarButtonEvents_ClickEventHandler(buttonOne_Click);
                    newMenuBar.Visible = true;
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }

        private void buttonOne_Click(Office.CommandBarButton ctrl,
            ref bool cancel)
        {
            System.Windows.Forms.MessageBox.Show("You clicked: " + ctrl.Caption,
                "Custom Menu", System.Windows.Forms.MessageBoxButtons.OK);

        }


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

        private void createnewform()
        {
            SAmple_form sform = new SAmple_form();
            sform.Text = "Show the Count";


        }

        #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
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Xml.Linq;
使用Outlook=Microsoft.Office.Interop.Outlook;
使用Office=Microsoft.Office.Core;
使用System.Windows.Forms;
名称空间Sql_openertake1
{
公共部分类ThisAddIn
{
private Office.CommandBar menuBar;
private Office.CommandBar弹出新菜单栏;
私人办公室。命令按钮按钮无;
Office.CommandBarButton PacktButtonA;
Office.CommandBar PacktCustomToolBar;
私有void ThisAddIn_启动(对象发送方,System.EventArgs e)
{
//验证PacktCustomToolBar是否存在并添加到应用程序
if(PacktCustomToolBar==null)
{
//将命令栏添加到活动资源管理器
Office.commandbar packtbar=此.Application。
ActiveExplorer().commandbar;
//将PacktCustomToolBar添加到命令栏
PacktCustomToolBar=PacktBars.Add(“SQL Opener”,Office.MsoBarPosition.msoBarTop,false,true);
}
//将按钮添加到自定义工具栏
Office.CommandBarButton MyButton1=(办公室。
CommandBarButton)PacktCustomToolBar.Controls.Add(1,
失踪,失踪,失踪,失踪);
//设置按钮样式
MyButton1.Style=Office.MsoButtonStyle.msoButtonCaption;
//设置标题和标记字符串
MyButton1.Caption=“打开”;
MyButton1.Tag=“我的按钮”;
if(this.PacktButtonA==null)
{
//为工具栏中的按钮添加事件处理程序
this.PacktButtonA=MyButton1;
PacktButtonA.单击+=新建办公室。
_CommandBarButtoneEvents\u ClickEventHandler(按钮单击);
}
}
//自定义工具栏中的按钮事件
私有无效按钮单击(Office.CommandBarButton buttonCtrl,
ref bool取消选项)
{
//单击按钮时显示的消息框
Show(ButtonControl.Caption+“向世界问好!”);
}
私有void AddMenuBar()
{
尝试
{
menuBar=this.Application.ActiveExplorer().commandbar.ActiveMenuBar;
newMenuBar=(Office.CommandBarPopup)menuBar.Controls.Add(
Office.MsoControlType.msoControlPopup,缺失,
失踪,失踪,真实);
if(newMenuBar!=null)
{
newMenuBar.Caption=“SQL Opener”;
buttonOne=(Office.CommandBarButton)newMenuBar.Controls。
添加(Office.MsoControlType.msoControlButton,缺少,
缺失,1,正确);
buttonOne.Style=Office.MsoButtonStyle。
msobuttonicon和caption;
buttonOne.Caption=“设置”;
buttonOne.FaceId=0548;
buttonOne.Tag=“c123”;
buttonOne.Click+=新建办公室。\u命令BarButtonEvents\u ClickEventHandler(buttonOne\u Click);
newMenuBar.Visible=true;
}
}
捕获(例外情况除外)
{
System.Windows.Forms.MessageBox.Show(例如Message);
}
}
私有无效按钮无单击(Office.CommandBarButton ctrl,
ref bool(取消)
{
System.Windows.Forms.MessageBox.Show(“您单击:”+ctrl.Caption,
“自定义菜单”,System.Windows.Forms.MessageBoxButtons.OK);
}
私有void ThisAddIn_关闭(对象发送方,System.EventArgs e)
{
}
私有void createnewform()
{
样本表格sform=新样本表格();
sform.Text=“显示计数”;
}
#区域VSTO生成的代码
/// 
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
/// 
私有void InternalStartup()
{
this.Startup+=new System.EventHandler(ThisAddIn\u启动);
this.Shutdown+=new System.EventHandler(ThisAddIn\u Shutdown);
}
#端区
}
}
这是我的xml数据

<?xml version="1.0" encoding="utf-8" ?>
<words>
    <word id="5001">None</word>
    <word id="5002">Glazed</word>
    <word id="5005">Sugar</word>
    <word id="5006">Sprinkles</word>
    <word id="5003">Chocolate</word>
    <word id="5004">Maple</word>

</words>

没有一个
光滑的
糖
洒
巧克力
枫树
谢谢你的帮助。