Bonzo:
How do I simply open a text file into a textbox? I know that in C++ I'd
use something like:
if(OpenDialog1->Execute())
Memo1->Lines->LoadFromFile(O penDialog1->FileName);
How can I do it in vsnet c#?
The RichTextBox class, for example, has a method called "LoadFile". Here's
some sample code copy-pasted from the .NET Framework help file:
public void LoadMyFile()
{
// Create an OpenFileDialog to request a file to open.
OpenFileDialog openFile1 = new OpenFileDialog( );
// Initialize the OpenFileDialog to look for RTF files.
openFile1.Defau ltExt = "*.rtf";
openFile1.Filte r = "RTF Files|*.rtf";
// Determine whether the user selected a file from the OpenFileDialog.
if(openFile1.Sh owDialog() == System.Windows. Forms.DialogRes ult.OK &&
openFile1.FileN ame.Length > 0)
{
// Load the contents of the file into the RichTextBox.
richTextBox1.Lo adFile(openFile 1.FileName,
RichTextBoxStre amType.PlainTex t);
}
}
--
take care,
Fabian Ottjes
Purposesoft (
http://www.purposesoft.com)
"There are gods, ... They're the most extraordinary beings on earth. Never
doubt it." -Swoop