title: How to search Textbox entered value in an xml file using C#
body: <p>I am a beginner in C#, Xml. If I have to enter a value (partnumber) in TextBox (say 704644-B21) , The partnumber should get searched in XML file, and display if it exists or not.</p>
  
  <pre><code>&lt;Processor&gt;
              &lt;Item&gt;
                &lt;partnumber&gt;678244-B21&lt;/partnumber&gt;
                &lt;processorname&gt; E5-2637 Kit&lt;/processorname&gt;
                &lt;processortype&gt;Dual Core&lt;/processortype&gt;
                &lt;quantity&gt;2&lt;/quantity&gt;
              &lt;/Item&gt;
   &lt;/Processor&gt;
   &lt;Interconnects&gt;
            &lt;Interconnect Bay="Bay1" partnumber="516733-B21"&gt;Ethernet -  6120XG Blade Switch&lt;/Interconnect&gt;
            &lt;Interconnect Bay="Bay2" partnumber="641146-B21"&gt;Ethernet -  Fabric Ext Module&lt;/Interconnect&gt;
            &lt;Interconnect Bay="Bay3" partnumber="516733-B21"&gt;Ethernet - HP ProCurve 6120XG Blade Switch(516733-B21)&lt;/Interconnect&gt;
            &lt;Interconnect Bay="Bay4" partnumber="658250-B21"&gt;Ethernet - XG Blade Switch&lt;/Interconnect&gt;
            &lt;Interconnect Bay="Bay5" partnumber="658250-B21"&gt;Ethernet - XG Blade Switch&lt;/Interconnect&gt;
            &lt;Interconnect Bay="Bay6" partnumber="438031-B21"&gt;Ethernet - BL-c Switch&lt;/Interconnect&gt;
            &lt;Interconnect Bay="Bay7" partnumber="451438-B21"&gt;Ethernet - Cisco Catalyst Blade Switch 3120G&lt;/Interconnect&gt;
            &lt;Interconnect Bay="Bay8" partnumber="658250-B21"&gt;Ethernet - XG Blade Switch(658250-B21&lt;/Interconnect&gt;
          &lt;/Interconnects&gt;
  &lt;/ModelDetails&gt; 
  </code></pre>
  
  <p>When i input the part number in the text box, I want to know through Messagebox, if the part number entered in the textbox, exist in the xml file or not. If the Part number exists, Message box should display "Partnumber {0] exist" , else it must display," Part number {0} does not exist."</p>
  
  <pre><code> private bool hasNode;
   XmlDocument xworkload = new XmlDocument();
  
  private void btnPnoCheck_Click(object sender, RoutedEventArgs e)
          {            
              Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
              dlg.FileName = "Document";
              dlg.DefaultExt = ".hpa";
              dlg.Filter = "Xml document (.hpa)|*.hpa";
  
              var result = dlg.ShowDialog();
              if(result==true)
              {
                  xworkload.Load(dlg.FileName);
  
                  string xmlcontents = xworkload.InnerXml;
  
                  string textToSearch = textBox1.Text;
  
                  bool hasnode = (xworkload.DocumentElement.SelectNodes("//Item/partnumber[text()='" + textToSearch + "']").Count &gt; 0) ;
  
                  if (!hasnode)
                  {
                      MessageBox.Show(String.Format("Part number {0}{1} found ", textBox1.Text, (!hasNode ? " not" : String.Empty)));
                  }
                  else
                      MessageBox.Show(String.Format("Part number {0} found" , textBox1.Text));               
  
              }
  
          }
  </code></pre>
  
  <p>The above code doesn't counts the partnumber inside 'Interconnects' tag</p>