I want to duplicate a line from a text file (.txt) and insert it above the line selected when a button is clicked
eg:
Tomato
Lemon
Apple
and I want to duplicate "Lemon" and insert it above when I click a button, like :
Lemon <- Inserted Line
I've tried :
void duplLine(string pathFile, int line) { List<string> tempFile = File.RealAllLines(pathFile).ToList(); tempFile.Add(tempFile[line]); File.writeAllLines(pathFile, tempFile.ToArray(); }
It worked perfectly but the line was inserted at the END like :
Lemon <- Inserted Line (This should be at the index 2)
Thanks