how to read txt file

  • Thread starter Thread starter Riccio
  • Start date Start date
Hi,

If you add the file into your project this file is copied on the solution
folder and not on the "Bin" folder, therefore if you need to read it you need
to copy it on the BIN folder or add a PostBuild event to copy the file
(usually what I do).

Then to read the file you can use the FileStream


using (StreamReader ReadStream = System.IO.File.OpenText("yourFile.txt"))
{
string Content = ReadStream.ReadToEnd();
}

Cheers
 
Riccio said:
Project/add/existing item/File type *.* --> temp.txt
how to read temp.txt

Salvador's answer is fine for "content" resources, but I'd suggest
making the file an embedded resource unless it actually needs to be
changed after build. Then you can use
Assembly.GetManifestResourceStream to open a stream, and wrap a
StreamReader round it. It makes life easier if you only have to copy
the assembly around, rather than other files as well :)
 
Back
Top