Display html/css web page in C# Application?

I am currently developing an application for my website (file downloader/updater) and I would like to create a block within my application that reads and displays a html web page from my website within the C# application.

This html/css page would be very simple (recent change log or dev blog).

How can I red and display the html page within my C# application?

For example, I want the html page content to be displayed in the blank space in this application http://puu.sh/5BFcv.png

Answers


If you're developing for Winforms/WPF, you should be able to use the standard WebBrowser control to display HTML. Although it's powered on IE7+ I believe, you stated that you only need to display a bit of data, so it'll probably work out fine.

Or you can take a look at the HTML Renderer project on Codeplex and use that if the default WebBrowser control doesn't work out for you (broken pages).

Also, a side note: For something as simple as a changelog delivering mechanism, I'd personally avoid using a Webbrowser to display HTML. Why not retrieve the changelog in plain text format and populate the information natively.

Sample code you can use to download a text file from a web server and set it as a label's text:

    public void Main()
    {
        using (WebRequest req = new WebRequest())
        {
            string downloadedChangelog = req.DownloadString(new Uri("http://www.site.com/changelog.txt"));
            changelogLabel.Text = downloadedChangelog;      
        }
    }

Or, if you want to make the downloading string part asynchronous (won't freeze the UI), you can do this:

    public void Main()
    {
        using (WebClient client = new WebClient())
        {
            client.DownloadStringCompleted += client_DownloadStringCompleted;
            client.DownloadStringAsync(new Uri("http://www.google.com"));
        }
    }

    private void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        changelogLabel.Text = e.Result.ToString();
    }

Make sure to put a using System.Net; statement at the top of your code, or type it all out.


Try to add a WebBrowser controls to your app.


Need Your Help

Cordova backbutton not working

javascript android html5 cordova

I have a problem that Cordova event on the Back button does not do anything yet to execute alert ("").

epub2pdf paginate the html format

objective-c c pdf epub

I am working on a project which needs to convert epub to pdf.