Search code examples
c#messagebox

How are going to read a text file and auto save in c #


ex: if the text file has the apple - Messagebox.Show("This word is exist");

else

Messagebox.Show("The word does not exist!");
and if none of these words in the text file will be automatically saved and automatic make a new line for word does not exist in the text file.


Solution

  • read all text

      string fileText = File.ReadAllText("filePath");
      if (fileText.Contains("apple"))
      {
           Messagebox.Show("This word is exist");
      }
      else
      {
           Messagebox.Show("The word does not exist!");
           File.AppendAllText(@"filePAth", "The word does not exixt in the text file" + Environment.NewLine);
      }