title: How to close file that has been read
body: <p>So im trying to close a file (transactions.txt) that has been open that i've used to read into a textbox and now I want to save back to the file but the problem debug says that the file is in use so I need to find a way to close it. Can anyone help me with this? Thanks!</p>
  
  <pre><code>        SearchID = textBox1.Text;
          string ID = SearchID.ToString();
          bool idFound = false;
          int count = 0;
  
          foreach (var line in File.ReadLines("transactions.txt"))
          {
  
              //listView1.Items.Add(line);
  
              if (line.Contains(ID))
              {
                  idFound = true;
              }
  
              //Displays Transactions if the variable SearchID is found.
              if (idFound &amp;&amp; count &lt; 8)
              {
                  textBox2.Text += line + "\r\n";
                  count++;
  
              }
          }
      }
  
      private void SaveEditedTransaction()
      {
          SearchID = textBox1.Text;
          string ID = SearchID.ToString();
          bool idFound = false;
          int count = 0;
  
          foreach (var lines in File.ReadLines("transactions.txt"))
          {
  
              //listView1.Items.Add(line);
  
              if (lines.Contains(ID))
              {
                  idFound = true;
              }
  
              if (idFound)
              {
                  string edited = File.ReadAllText("transactions.txt");
                  edited = edited.Replace(lines, textBox2.Text);
                  File.WriteAllText("Transactions.txt", edited);
              }
  </code></pre>