Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 4 - Displaying HTML Content with a Web Browser...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Displaying HTML Content with a Web Browser Control in Visual Basic
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 21
    2006-05-10

    Table of Contents:
  • Displaying HTML Content with a Web Browser Control in Visual Basic
  • Embedding a web browser control into a Windows form
  • Creating a user interface for testing
  • How to display HTML content generated by a program

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Displaying HTML Content with a Web Browser Control in Visual Basic - How to display HTML content generated by a program


    (Page 4 of 4 )

    There are instances when you would like to display some HTML content produced by an application. But just passing the content to the Navigate() method will not work unless it is embedded in a file. If you were to use an HTML editor, it is very easy to pass the HTML content as an argument, and voila! You have a display of the HTML rendered on a web page. However it is possible to render the display if it can be converted to a file and stored in some location. This section shows how you may be able to do this.

    In order to access the input/output capabilities you need to call up a reference to the FileSystemObject. Similar to adding the component to the project, you can also establish reference to libraries by clicking on Project -> References, and from the window that shows up scroll down and select the reference to the Microsoft Script Runtime. This adds the scrrun.dll, which gives access to the FileSystemObject as shown in the object browser in Fig.6.

    Fig.6

    Now modify the code by adding another button, to whose click event you will add the code shown below. The function call collects the textbox contents and presents it to the outstream. The outstream uses the WriteLine() method to write the text collected to the CFtest.htm file. This file gets persisted to the "C:inetpubwwwroot" directory. The WebBrowser control can now navigate to this file using the path reference to the file.

    Private Sub Command2_Click()
    Dim strg
    strg = Text1.Text
    Call browse (strg)
    End Sub
    Private Sub Form_Load()
    WebBrowser1.Visible = False
    End Sub
    Sub browse (ByVal stringi As String)
    WebBrowser1.Visible = True
    Dim fsys As New FileSystemObject
    Dim outstream As TextStream
    testfile = "C:inetpubwwwrootcftest.htm"
    Set outstream = fsys.CreateTextFile(testfile, True, False)
    outstream.WriteLine (stringi)
    Set outstream = Nothing
    WebBrowser1.Navigate2 ("http://localhost/cftest.htm")
    End Sub
    

    Now by running this project you can verify that the display indeed shows the HTML content as shown in Fig.7.

    Fig.7

    Summary

    The web browser control is a very important ActiveX control for Internet applications. It can be used to display a web page or HTML content. It can also be used for displaying a Word document, RTF document, or XML document inside a Windows form. For example it is possible to create a help file using this control for Windows form-based applications.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Web browser control is a very useful ActiveX control. There is a .NET twin as well...
       · Yikes! I don't know about your researching skills. Check out the following MSDN...
       · Thanks for the comment and drawing my attention to the MSDN article. This article...
     

    VISUAL BASIC.NET ARTICLES

    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT