At a guess,
; you are trying to read from and write to the same file.
Your code opens a
for the path, but never closes it. You then try to open a
to the same path, but the file is locked by your own code.
Change your code so that your
is closed before you try to write to the file:
using (StreamReader reader = new StreamReader(path))
line = reader.ReadToEnd();
Better yet, use the utility methods in the
string line = File.ReadAllText(path);