title: VSTO outlook scan opened item
body: <p>Mine is a bit of odd solution.
  I want to scan for a particular string of words (these particular string of words are already in an XML data file) to achieve this i have thought of going this thru these following steps
   I will have a menubaritem to change settings of the add-in(not necessary now)
  I will have a button like the new button in the bar like this </p>
  
  <p><img src="https://i.stack.imgur.com/3szWF.png" alt="http://www.packtpub.com/sites/default/files/Article-Images/vsto-article1-image5.png"></p>
  
  <p><a href="http://www.packtpub.com/article/microsoft-office-outlook-programming-vsto-c-sharp-part1" rel="nofollow noreferrer">http://www.packtpub.com/article/microsoft-office-outlook-programming-vsto-c-sharp-part1</a></p>
  
  <p>then say the user is reading an item that is selected and opened in the reading pane. when my button is pressed i want the code to scan the subject and the body to match with my xml data, if it exists then show a message box.</p>
  
  <p>I did as far as creating a menuitem and menubar button and the xml data, now my question is how to scan the currently being read item?</p>
  
  <p>This is my C# code in thisaddin.cs</p>
  
  <pre><code>  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
  
          /// &lt;summary&gt;
          /// Required method for Designer support - do not modify
          /// the contents of this method with the code editor.
          /// &lt;/summary&gt;
          private void InternalStartup()
          {
              this.Startup += new System.EventHandler(ThisAddIn_Startup);
              this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
          }
  
          #endregion
      }
  }
  </code></pre>
  
  <p><strong>this is my xml data</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;words&gt;
      &lt;word id="5001"&gt;None&lt;/word&gt;
      &lt;word id="5002"&gt;Glazed&lt;/word&gt;
      &lt;word id="5005"&gt;Sugar&lt;/word&gt;
      &lt;word id="5006"&gt;Sprinkles&lt;/word&gt;
      &lt;word id="5003"&gt;Chocolate&lt;/word&gt;
      &lt;word id="5004"&gt;Maple&lt;/word&gt;
  
  &lt;/words&gt;
  </code></pre>
  
  <p>thanks for the help.</p>