HTML file
HTML file
HTML file
HTML file
HTML file
HTML file HTML file HTML file HTML file HTML file HTML file HTML file HTML file
HTML file HTML file
HTML file
Go Back  Xtreme Visual Basic Talk > > > HTML file


Reply
 
Thread Tools Display Modes
  #1  
Old 10-12-2009, 01:39 PM
mrphysics mrphysics is offline
Newcomer
 
Join Date: Aug 2004
Posts: 12
Default HTML file


Ok, I want to create an html file that will display data from a text file. For example, the text file might contain data in a grid 6 across by say some number down. I would like to be able to read in the text file (which I can do), and then output an html file that now displays the data in a nice format (maybe even with some dividing lines. Can anyone point me in the correct direction on how to create an html file? Maybe even with some formatting?

Thanks,
mrphysics
Reply With Quote
  #2  
Old 10-12-2009, 11:39 PM
Qua's Avatar
QuaHTML file Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

You could go ahead and use the HtmlDocument class to build up the document structure and fill it with data before writing it to a file or you can open a file and output HTML to it manually.

If you use the HtmlDocument class then you will have some nice methods to assist you but as tradeoff you will have to spend a little time learning your way around the class. You can check out the MSDN link to the class, it contains an example of reading from a database and outputting it to an html file - basically same methodology as you.

As for the HTML itself I suggest you use the Table tag to format your data. It is meant for showing tabulated data and it also allows you to do some pretty nifty formatting.
__________________
Reading is the foundation for all knowledge - Unknown.
Reply With Quote
  #3  
Old 10-13-2009, 07:44 AM
AtmaWeapon's Avatar
AtmaWeaponHTML file AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Could you provide an example of using HtmlDocument as you explained, Qua? This is something I've tried in the past and failed. There's no constructor and no shared methods. The only way I can see to get one is to use a WebBrowser control, but I've had problems loading specific on-disk files. In addition, I don't see anything that looks like it would save the document. Even looking at the unmanaged interfaces like IHTMLDocument2, everything leads me to believe this class is for the display and manipulation of HTML documents in IE windows, not in files.

I'm hoping I'm wrong and I've just missed the API to do it. It sounds like the OP's requirements involve first converting a text file to HTML, then displaying that HTML. Based on my experience, I'd say it's probably roughly as easy to use the DataGridView control and skip the HTML conversion.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #4  
Old 10-13-2009, 08:58 AM
Qua's Avatar
QuaHTML file Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

Quote:
Originally Posted by AtmaWeapon View Post
Could you provide an example of using HtmlDocument as you explained, Qua? This is something I've tried in the past and failed. There's no constructor and no shared methods. The only way I can see to get one is to use a WebBrowser control, but I've had problems loading specific on-disk files. In addition, I don't see anything that looks like it would save the document. Even looking at the unmanaged interfaces like IHTMLDocument2, everything leads me to believe this class is for the display and manipulation of HTML documents in IE windows, not in files.

I'm hoping I'm wrong and I've just missed the API to do it. It sounds like the OP's requirements involve first converting a text file to HTML, then displaying that HTML. Based on my experience, I'd say it's probably roughly as easy to use the DataGridView control and skip the HTML conversion.
You're absolutely correct. I missed that they made the constructor internal, so there's no way to utilize the class besides going through the webbrowser class.

I found this other library which seemes rather awesome if it works. It's called SGMLReader and it's capable of parsing among other things HTML. Definitely worth checking out.
__________________
Reading is the foundation for all knowledge - Unknown.
Reply With Quote
  #5  
Old 11-04-2009, 03:05 PM
mrphysics mrphysics is offline
Newcomer
 
Join Date: Aug 2004
Posts: 12
Default

All,

Well after investigating the Webbrowser class etc., I decided to take the easy route. Rather than writing a text file out, I just imported my data into Excel. I then wrote a VBA macro to manipulate the data (format, sort, etc.) and then save it to an HTML file. It was a whole bunch easier and quicker. I would still like to know how to create an HTML file from VB, as I think it would be very useful, but for now this method seems to work. If anyone is interested in my VBA code, I would be willing to post it.

Thanks,
A. West
Reply With Quote
  #6  
Old 09-14-2010, 07:12 AM
mrphysics mrphysics is offline
Newcomer
 
Join Date: Aug 2004
Posts: 12
Default Success....

All,

Well, for reasons I had to try and get my original idea working. So....after some time and research I have some working code. Basically I have a form with a WebBrowser and RichText controls on it. I have provide below some code that does what I want. It is not finished yet (needs some additional formatting etc.), but it works. Hopefully someone can use this as well.
Code:
        If (Not (WebBrowser1.Document Is Nothing)) Then
            With WebBrowser1.Document

                Dim doc As HtmlDocument
                Dim TableElem As HtmlElement
                Dim strElemTag As String = "TABLE border=1"
                TableElem = .CreateElement(strElemTag)
                WebBrowser1.Document.Body.AppendChild(TableElem)

                Dim TableRow As HtmlElement
                Dim TableHeader As HtmlElement

                ' Create the table header. 
                TableHeader = .CreateElement("THEAD")
                TableElem.AppendChild(TableHeader)
                TableRow = .CreateElement("TR")
                TableHeader.AppendChild(TableRow)

                Dim HeaderElem As HtmlElement
                For Each fld In rs.Fields
                    HeaderElem = .CreateElement("TH")
                    HeaderElem.InnerText = fld.Name
                    TableRow.AppendChild(HeaderElem)
                Next fld

                ' Create table rows.
                Dim TableBody As HtmlElement
                Dim TableCell As HtmlElement
                TableBody = .CreateElement("TBODY")
                TableElem.AppendChild(TableBody)

                While Not rs.EOF
                    TableRow = .CreateElement("TR")
                    TableBody.AppendChild(TableRow)
                    For Each fld In rs.Fields
                        TableCell = .CreateElement("TD")
                        TableCell.InnerText = CStr(fld.Value)
                        TableRow.AppendChild(TableCell)
                    Next fld
                    rs.MoveNext()
                End While
                'Next intI
            End With
        End If

        Dim elem As HtmlElement
        If (WebBrowser1.Document IsNot Nothing) Then
            Dim elems As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("HTML")
            If (elems.Count = 1) Then
                elem = elems(0)
                RichTextBox1.Text = elem.OuterHtml
                Debug.Print(RichTextBox1.Text)
            End If
        End If

        RichTextBox1.SaveFile("C:\Documents and Settings\xxxxxx\Desktop\test1.html", RichTextBoxStreamType.PlainText)
"Use in good health...."
MrPhysics
Reply With Quote
  #7  
Old 09-15-2010, 03:15 PM
mrphysics mrphysics is offline
Newcomer
 
Join Date: Aug 2004
Posts: 12
Default Maybe a better way

I had been working on two ways to create an html file from VB. One way using htmldocument, and another which I found on http://couchware.ca/blogs/cam/2009/0...ment-with-net/

The second way uses the xmlDocument class. Here is some sample code.
Code:
        ' Create a new XML document.
        Dim xmlDoc As XmlDocument = New XmlDocument
        ' Create the html tag.
        Dim xmlRoot As XmlElement = xmlDoc.CreateElement("html")
        xmlDoc.AppendChild(xmlRoot)

        ' Create the head tag and append it under the html element.
        Dim xmlHead As XmlElement = xmlDoc.CreateElement("head")
        xmlRoot.AppendChild(xmlHead)

        ' Create the title tag, set it's text to "Database Table"
        ' and append it under the head element.
        Dim xmlTitle As XmlElement = xmlDoc.CreateElement("title")
        xmlTitle.AppendChild(xmlDoc.CreateTextNode("Database Table"))
        xmlHead.AppendChild(xmlTitle)
        ' Create the body element and append it to the root.
        Dim xmlBody As XmlElement = xmlDoc.CreateElement("body")
        xmlRoot.AppendChild(xmlBody)

        ' Create the table and append it.
        Dim xmlTable As XmlElement = xmlDoc.CreateElement("table")
        xmlBody.AppendChild(xmlTable)

        Dim attTable As XmlAttribute = xmlDoc.CreateAttribute("border")
        attTable.Value = "1"
        xmlTable.SetAttributeNode(attTable)

        Dim xmlTableHead As XmlElement = xmlDoc.CreateElement("thead")
        xmlTable.AppendChild(xmlTableHead)

        Dim xmlTableRow As XmlElement
        xmlTableRow = xmlDoc.CreateElement("tr")
        xmlTableHead.AppendChild(xmlTableRow)

        'Define/fill header cells
        Dim xmlHeadElem As XmlElement
        For Each fld In rs.Fields
            xmlHeadElem = xmlDoc.CreateElement("th")
            xmlHeadElem.InnerText = fld.Name
            xmlTableRow.AppendChild(xmlHeadElem)
        Next fld

        'Create table rows
        Dim xmlTableBody As XmlElement
        Dim xmlTableCell As XmlElement
        xmlTableBody = xmlDoc.CreateElement("TBODY")
        xmlTable.AppendChild(xmlTableBody)

        For intI = 1 To 10
            'While Not rs.EOF
            xmlTableRow = xmlDoc.CreateElement("TR")
            xmlTableBody.AppendChild(xmlTableRow)
            For Each fld In rs.Fields
                'Dim Item As Object = Row(Col)
                xmlTableCell = xmlDoc.CreateElement("TD")
                'If Not (TypeOf (Item) Is DBNull) Then
                'TableCell.InnerText = CStr(Item)
                xmlTableCell.InnerText = CStr(fld.Value)
                'End If
                xmlTableRow.AppendChild(xmlTableCell)
            Next fld
            rs.MoveNext()
            'End While
        Next intI
Hopefully it helps someone some where.

mrphysics
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
HTML file
HTML file
HTML file HTML file
HTML file
HTML file
HTML file HTML file HTML file HTML file HTML file HTML file HTML file
HTML file
HTML file
 
HTML file
HTML file
 
-->