C# text file search for specific word and delete whole line of text that contains that word

The easiest is to rewrite the whole file without the line(s) that contain the word. You can use LINQ for that:

var oldLines = System.IO.File.ReadAllLines(path);
var newLines = oldLines.Where(line => !line.Contains(wordToDelete));
System.IO.File.WriteAllLines(path, newLines);

If you only want to delete all lines that contain the word(not only the sequence of characters), you need to split the line by ' ':

var newLines = oldLines.Select(line => new { 
            Line = line, 
            Words = line.Split(' ') 
        })
        .Where(lineInfo => !lineInfo.Words.Contains(wordToDelete))
        .Select(lineInfo => lineInfo.Line);

You can do it easily without LINK

                string search_text = text;
                string old;
                string n="";
                StreamReader sr = File.OpenText(FileName);
                while ((old = sr.ReadLine()) != null)
                {
                    if (!old.Contains(search_text))
                    {
                        n += old+Environment.NewLine;  
                    }
                }
                sr.Close();
                File.WriteAllText(FileName, n);

Code:

"using System.Linq;" is required.

Write your own extension method IsNotAnyOf(,) (put it in a static class) and call the method (i. e. it is called) from .Where(n => n.IsNotAnyOf(...))...(); The for-loop will return false if the condition is met, if not the method will return true:

static void aMethod()
{
    string[] wordsToDelete = { "aa", "bb" };
    string[] Lines = System.IO.File.ReadAllLines(TextFilePath)
        .Where(n => n.IsNotAnyOf(wordsToDelete)).ToArray();
    IO.File.WriteAllLines(TextFilePath, Lines);
}

static private bool IsNotAnyOf(this string n, string[] wordsToDelete)
{    for (int ct = 0; ct < wordsToDelete.Length; ct++)
         if (n == wordsToDelete[ct]) return false;
     return true;
}