C#: Remove line from textfile

With the following code you can remove a line from a textfile (web.config). If the string is within a line the line will be removed.


string configFile = @"C:devweb.config";
List lineList = File.ReadAllLines(configFile).ToList();
lineList = lineList.Where(x => x.IndexOf("<!--") <= 0).ToList();
File.WriteAllLines(configFile, lineList.ToArray());


Leave a Reply

Your email address will not be published. Required fields are marked *