Solved

How can I create an html page programattically Can it be done?

Posted on 2007-04-05
4
196 Views
Last Modified: 2010-04-23
Can this be done ....

I simply want to create a html page that I can then display in a webBrowser control from a single button click ...

NOTE:  I would like to take the contentsd of around 6 textboxes that will be in the html page  such as a title, description and author name such like ....  then once the textboxes are filled click a button and the html page is created.
Then I want to display it in an webBrowser control  .....  I know how to display it once the html page is created ... its knowing how to create the html syntax for the page is where I am lost

All help is appreciated

Mark
0
Comment
Question by:vbMarkO
  • 2
4 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 18861012
At it's simplest...

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim strHtml As New System.Text.StringBuilder
        strHtml.Append("<html><body>")
        strHtml.Append("<b>" & TextBox1.Text & "</b><br>") ' bold first line
        strHtml.Append(TextBox2.Text & "<br>")
        strHtml.Append(TextBox3.Text & "<br>")
        strHtml.Append("</body></html>")
        WebBrowser1.Navigate("about:" & strHtml.ToString)
    End Sub

End Class
0
 
LVL 27

Expert Comment

by:VBRocks
ID: 18862326
Just an additional comment:  You can write it out to a file with a ".html" extension.  If you write it out to an actual website directory, you'll be able to link to it as well.

Dim sw as New System.IO.StreamWriter("C:\MyPath\MyWebPage.html", False)
sw.WriteLine "<html>"
sw.WriteLine "<head>"
sw.WriteLine "<title>My Web Page Rocks!</title>"
sw.WriteLine "</head>"
sw.WriteLine "<body><h1>This is my page!</h1></body>"
sw.WriteLine "</html>"

sw.Close()
sw.Dispose()
0
 

Author Comment

by:vbMarkO
ID: 18862874
Ok I am giving these a go   running into soe trouble here it may be that this cant be done or more likely I ma just doing it all wrong ...

I am trying the first solution this way

strHtml.Append("<link" & "rel=" & ""stylesheet" " & "type=" & ""text/css" " & "href=" & ""style.css"" & " />")

The above is supposed to come out like below  ..... but I am getting a blue underline under stylesheet above

<link rel="stylesheet" type="text/css" href="style.css" />

I know this more complex than what you example was but can I do this with what you were doing?

Here is what I have before the above

strHtml.Append("<html><head>")
strHtml.Append("<title>" & "The Church of God Ministers Report" & "</title>") ' <title>The Church of God Minsiters Report</title>
THEN
strHtml.Append("<link" & "rel=" & ""stylesheet" " & "type=" & ""text/css" " & "href=" & ""style.css"" & " />")

this is where I am getting the error ... the blue underlinning stylesheet


0
 

Author Comment

by:vbMarkO
ID: 18862909
I fixed it and I find this solution to be my fix ....

strHtml.Append("<link rel=""stylesheet"" type=""text/css"" href=""style.css"" />")

That resolved my error ....

I appreciate showing how to write to an html file but the other is really what I am wanting  
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question