Hi, I want to know, how I can load all text from some webpage in to my C# aplication RichTextBox?

Recommended Answers

All 3 Replies

That isn't going to work quite the way you think if you want the formatted text. Websites use a combination of CSS, in-line styling, javascript after the page loads, and probably other means of formatting a site.

Do you want *just* the text or do you want to display the text all pretty and formatted?

I need only webpage text. It is like i go to some web page then slect all text (ctrl + a), and copy that text in to notepad. In this case i need that my C# aplication copy that text automatically in to rich textbox.

Here is code that will do what you originally asked. Just set your richTextBox1.Text = webHTMLText;, after running it.

string webHTMLText;
            WebClient webClient = new WebClient();

            using (MemoryStream ms = new MemoryStream(webClient.DownloadData("http://daniweb.com/")))
            {
                using (StreamReader sr = new StreamReader(ms))
                {
                    webHTMLText = sr.ReadToEnd();
                    sr.Close();
                }
            }

If there is specific text you want from this before you put it into the control's Text, you would need to know exactly what tags to parse it out of.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.