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.
StreamReader sr = new StreamReader(@"C:\abc.txt");
string line;
line = sr.ReadLine();
while (line != null)
{
  if (line.StartsWith("<"))
  {
    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();
Here I am getting the error file is already open by another process.
Please help me, anyone. Main task is to overwrite the same texfile with modifications