Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to open a file in my richtextbox.

this is my code which runs when i click on open in open dialog.

C#
Stream open;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
    try
    {
        if ((open = openFileDialog1.OpenFile()) != null)
        {
            open.Close();
            StreamReader r = new StreamReader(openFileDialog1.FileName);
            richTextBox1.Text = r.ReadToEnd();
            r.Close();
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show("Could not read File!" + ex.Message, " Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }

}


i dont get any error but nothing appears in richtextbox.
Posted

1 solution

You should check that the file you are trying to open contains something. I just tried your exact code with a text(.txt) file and it works perfectly, so there is nothing wrong with the code.
 
Share this answer
 
Comments
Sweety Khan 24-Aug-11 10:23am    
lOl i became tired, closed the thinkpad and now i open, it is working. dont know wht happen before . btw thanx a lot

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900