T
Tony Johansson
Hello!
I have this eventhandler method OpenToolStripMenuItem_Click shown below.
When statement richTextBox.Rtf = contents;
is executed I get following error message "Can't read fileFile format is not
valid" from the catch handler.
The file that I open by using openFileDialog has filename test.txt and
contains this text "This is a test by me."
Can somebody explain why I get this kind of error message ?
private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
Stream streamInp = openFileDialog.OpenFile(); //Open the specified
file
if (streamInp != null)
{
//If the file was successfully opened get a StreamReader
StreamReader streamRdr = new StreamReader(streamInp);
//Read the entire file into the richTextBox
string contents = streamRdr.ReadToEnd();
richTextBox.Rtf = contents;
streamRdr.Close();
}
}
}
catch (Exception ex)
{
richTextBox.Text = "Can't read file";
richTextBox.Text += ex.Message;
}
}
//Tony
I have this eventhandler method OpenToolStripMenuItem_Click shown below.
When statement richTextBox.Rtf = contents;
is executed I get following error message "Can't read fileFile format is not
valid" from the catch handler.
The file that I open by using openFileDialog has filename test.txt and
contains this text "This is a test by me."
Can somebody explain why I get this kind of error message ?
private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
Stream streamInp = openFileDialog.OpenFile(); //Open the specified
file
if (streamInp != null)
{
//If the file was successfully opened get a StreamReader
StreamReader streamRdr = new StreamReader(streamInp);
//Read the entire file into the richTextBox
string contents = streamRdr.ReadToEnd();
richTextBox.Rtf = contents;
streamRdr.Close();
}
}
}
catch (Exception ex)
{
richTextBox.Text = "Can't read file";
richTextBox.Text += ex.Message;
}
}
//Tony