Hi
I want to display the html content of the web pages(url address) in a c# window applications, but it is possible to get the dynamic content of a web pages also.

If yes please query your comment.

Try code

private string GetHtmlFromUrl(string url)
    {
        string html = "";
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
        
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        // get the response stream.
        //Stream responseStream = response.GetResponseStream();
        // use a stream reader that understands UTF8
        StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
        html = reader.ReadToEnd();
        // close the reader
        reader.Close();
        response.Close();
        return html;//return conten html
    }

If you just want to display the webpage as it appears in your browser then the WebBrowser control is the easiest way to go. You jsut set the URL and it works like any other webbrowser, but its a control embedded in your program.

If you just want to display the webpage as it appears in your browser then the WebBrowser control is the easiest way to go. You jsut set the URL and it works like any other webbrowser, but its a control embedded in your program. this Click Here

in C# WebResponse return a StreamReader and we can get the content from StreamReader ..

            WebResponse webresponse ;
            webRequest = WebRequest.Create(textBox1.Text);
            webresponse = webRequest.GetResponse();
            inStream = new StreamReader(webresponse.GetResponseStream());
            textBox2.Text = inStream.ReadToEnd();

full source code...Get URL Content

Nathan

Edited 2 Years Ago by nathanmannar: y

This article has been dead for over six months. Start a new discussion instead.