open (print )a text file to the screen

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();

}
 
T

Tamas Demjen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top