How to Read and display HTML file in Windows form application

In this tutorial Raviteja Swayampu explained about how to read and display HTML file in windows forms application.In present windows stand alone applications you can see different links that redirects us to different websites and shows some images and video contents.Best example for this is Visual studio start page.

Featured Videos
News Feed

If you observe this images you can easy find that those are html links.When we opens visual studio it fetches the html file from server.In current tutorial we will see how to implement this by using WebBrowser control in windows forms application.

Read and Display HTML file in Windows form

1.Create window form application in visual studio.
2.Prepare a html file with image and some text to input for windows form application.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <p>A famous quote of steev is</p>
    <hr />
    <img src='' />

3.Namespaces need to import for this application is as follows
Imports System.IO
Imports System.Reflection

4.Write below code in Form_Load method.
private void Form1_Load(object sender, EventArgs e)
            Assembly assembly = Assembly.GetExecutingAssembly();
            StreamReader reader = new StreamReader(assembly.GetManifestResourceStream("WebBrowser_HTML_File_CS.sample.htm"));
            webbrowser.DocumentText = reader.ReadToEnd(); 

5.If you observer the above code the html file is loaded into StreamReader object  using  GetManifestResourceStream method.The contents of stram reader are read using ReadToEnd method and assigned to WebBrowser control to display html file in windows forms application.
6.Final output of the application is look like below.

7.Download the source code for this application from here Download.

How to Read and display HTML file in Windows form application How to Read and display HTML file in Windows form application Reviewed by raviteja swayampu on 07:55:00 Rating: 5

No comments: