openFileDialog beginner's problem

  • Thread starter Thread starter Bonzo
  • Start date Start date
B

Bonzo

Hi,

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

How can I do it in vsnet c#?

THX
Libor(Czech rep.)
 
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(OpenDialog1->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.DefaultExt = "*.rtf";
openFile1.Filter = "RTF Files|*.rtf";

// Determine whether the user selected a file from the OpenFileDialog.
if(openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
openFile1.FileName.Length > 0)
{
// Load the contents of the file into the RichTextBox.
richTextBox1.LoadFile(openFile1.FileName,
RichTextBoxStreamType.PlainText);
}
}

--
take care,
Fabian Ottjes
Purposesoft (http://www.purposesoft.com)

"There are gods, ... They're the most extraordinary beings on earth. Never
doubt it." -Swoop
 
Great, Thanks


Fabian Ottjes said:
Bonzo:


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.DefaultExt = "*.rtf";
openFile1.Filter = "RTF Files|*.rtf";

// Determine whether the user selected a file from the OpenFileDialog.
if(openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
openFile1.FileName.Length > 0)
{
// Load the contents of the file into the RichTextBox.
richTextBox1.LoadFile(openFile1.FileName,
RichTextBoxStreamType.PlainText);
}
}

--
take care,
Fabian Ottjes
Purposesoft (http://www.purposesoft.com)

"There are gods, ... They're the most extraordinary beings on earth. Never
doubt it." -Swoop
 
Back
Top