Jump to content

load textfile to richtextbox

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
Hello,

Wondering if I am doing this write, I have the code below, but for some reason, it says text is invalid (runtime error) wondering If i am doing it right, here is the code below:



OpenFileDialog dlg = new OpenFileDialog();


        private void btnbrowse_Click(object sender, EventArgs e)

        {            

            dlg.Filter = "Text Documents only (*.txt)|*.txt|All Files|*.*";

            if (dlg.ShowDialog() == DialogResult.OK)

            {

                txtbrowse.Text = dlg.FileName;

            }

            else

            {

                MessageBox.Show("Please choose a Text File");

            }

            rchtxtdecrypt.LoadFile(txtbrowse.Text);


        }



#2
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
Hello,

Sorry I forgot to add,

I want the user to be able to click on the browse button, browse around for only textfiles (got that already) and when they click open, it displays whats inside the textfile into the richtextbox.

#3
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
got it nevermind, let me know if anyone wants to see it i be happy to show... you know what, forget it, i will show two different ways:


rchtxtdecrypt.LoadFile(txtbrowse.Text, RichTextBoxStreamType.PlainText);


and this way which is what i stumbled on

private void btnbrowse_Click(object sender, EventArgs e)

        {

            dlg.Filter = "Text Documents only (*.txt)|*.txt|All Files|*.*";

            if (dlg.ShowDialog() == DialogResult.OK)

            {

                txtbrowse.Text = dlg.FileName;

                rchtxtdecrypt.Clear();

                rchtxtdecrypt.Text = File.ReadAllText(dlg.FileName);

            }

            else

            {

                MessageBox.Show("Please choose a Text File");

            }


        }



#4
ArekBulski

ArekBulski

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,376 posts
Sorry, I saw this thread just now. I see you found the File.ReadXXX() three methods. They are very handy. ;)