open (print )a text file to the screen

  • Thread starter Thread starter Allen
  • Start date Start date
A

Allen

Can anybody tell me how to open (print)a text file to the screen. For
example, to click a botton and the file will be shown in the screen. Using
something like the code below.(the code below is not good, but I want to
give you an idea)

private: System::Void ShwCrdBtn_Click(System::Object^ sender,
System::EventArgs^ e)

{
FileInfo^ fi = gcnew FileInfo("C:\\MyFile.txt");
fi->OpenRead();

}
 
Can anybody tell me how to open (print)a text file to the screen. For
example, to click a botton and the file will be shown in the screen.

The easiest way is to use File.ReadAllText:
http://msdn.microsoft.com/en-us/library/ms143368.aspx

Example:
String^ content = System::IO::File::ReadAllText("c:\\test.txt");

Once you have the string read, you can assign it to a text box or a
label, or print it to the console, like this:

textBox1->Text = content;

or

Console::WriteLine(content);

Tom
 
Back
Top