title: Reading input value from textbox, fetching the data from Textfile and displaying the result
body: <p>I need help in searching the text file. I have manage to store the input values to Textfile with <code>":"</code> separator.</p>
  
  <p>And my result text box is like</p>
  
  <pre><code>friend1:126457890
  friend2:123487012
  Friend3:798461598
  </code></pre>
  
  <p>and now I want to search the text file and display result in <code>labels/textbox(read only)</code></p>
  
  <p>Here is my code to search</p>
  
  <pre><code> private void btn_search_search_Click(object sender, EventArgs e)
   {
          try
          {
              if (string.IsNullOrEmpty(txt_search.Text))
              {
                  lbl_search_error.Text = "Please Enter name to search";
              }
              else
              {
                  StreamReader sr = new StreamReader(@"path.txt");
  
                  string line;
                  string searchkey = txt_search.Text;
                  sr.ReadToEnd();
  
                  while ((line = sr.ReadLine()) != null)
                  {
  
                      if (line.Contains(searchkey))
                          break;
                  }
                  sr.Close();
  
                  string[] data = line.Split(':');
                  txt_result_name.Text = data[0];
                  txt_result_phno.Text = data[1];
              }
          }
          catch (Exception ex)
          {
              lbl_search_error.Text = ex.Message;
          }
  }
  </code></pre>
  
  <p>but I get</p>
  
  <blockquote>
    <p><em>Object reference not set to an instance of an object</em></p>
  </blockquote>
  
  <p>I tried to keep break point and chk, error is in this line</p>
  
  <pre><code>string[] data = line.Split(':');
  </code></pre>
  
  <p>Please help resolving</p>
  
  <p>Thank you for your time</p>