title: How to overwrite text in same text file
body: <p>I am in a fight with overwriting of a text file with some of changes using a console application. Here I am reading the file line by line. Can any one help me.</p>
  
  <pre><code>StreamReader sr = new StreamReader(@"C:\abc.txt");
  string line;
  line = sr.ReadLine();
  
  while (line != null)
  {
    if (line.StartsWith("&lt;"))
    {
      if (line.IndexOf('{') == 29)
      {
        string s = line;
        int start = s.IndexOf("{");
        int end = s.IndexOf("}");
        string result = s.Substring(start+1, end - start - 1);
        Guid g= Guid.NewGuid();
        line = line.Replace(result, g.ToString());
        File.WriteAllLines(@"C:\abc.txt", line );
      }
    }
    Console.WriteLine(line);
  
    line = sr.ReadLine();
  }
  //close the file
  sr.Close();
  Console.ReadLine();
  </code></pre>
  
  <p>Here I am getting the error <em>file is already open by another process</em>.</p>
  
  <p>Please help me, anyone. <strong>Main task is to overwrite the same texfile with modifications</strong></p>