Read a text file from local folder

Just because you added it to your solution doesn't mean the file gets placed into your output Build directory. If you want to use relative path, make sure your TextFile is copied during build to the output directory. To do this, in solution explorer go to properties of the text file and set Copy to Output Directory to Always or Copy if newer

Then you can use

File.Open("textfile.txt");

you need to use one of the following after the check you have made

 string path = @"\\TextConsole\testfile.txt";
 if (File.Exists(path))
 {
  FileStream fileStream = File.OpenRead(path); // or
  TextReader textReader = File.OpenText(path); // or
  StreamReader sreamReader = new StreamReader(path);
 }

Tags:

C#

File

File Io