Search This Blog

Friday, May 16, 2014

Change and replace text line in file C#

C# > IO > File > Read/Write Lines

ReadAllLines reads all lines of the file into a string array  and closes the file.
WriteAllLines creates a new file  writes strings to the file and closes the file.

Example:

Replace text line in a file

var lines = File.ReadAllLines(Pathfile);

lines[64] = "new text";


File.WriteAllLines(Pathfile);