2

I have created a program that merges files and I have decided to output the results as an HTML document so that it is legible. I have achieved this output using System.IO.StreamWriter and creating a textfile with all the html formatting and in-line CSS and saving it with the .html extension like so:

Dim lstrBackupOutput = "Test.html"
Dim lobjWriter As New System.IO.StreamWriter(lstrBackupOutput)
Dim lobjWriter as 
lobjWriter.WriteLine("<html>")
lobjWriter.WriteLine("</head>")
lobjWriter.WriteLine("<style type=""text/css""> h1,h2,h3{font-family:Arial, Serif;}  table{border-collapse:collapse; width:100%; font-family:Arial,Helvetica,Sans-serif;} th{height:30px;} td{text-align:left; padding:7px;} table, th, td{border:1px solid green;} </style>")
lobjWriter.WriteLine("</head>")

etc.

Is there more of a VB.NET way to do this? Most of my searches churn out ASP.NET results that don't seem to apply.

Thanks.

4
  • 1
    If you want an legible output have you considered XML and XLST? Commented Feb 24, 2012 at 11:59
  • Also, can you describe what you mean by "my searches churn out ASP.NET results that don't seem to apply"? Commented Feb 24, 2012 at 12:05
  • Well when I tried to reference htmltextwriter it didn't seem to find the reference in system. So I assumed it was just an asp thing =/ Commented Feb 24, 2012 at 13:13
  • I'll take a look at XML/XLST, it seems to be a popular answer :). thanks Commented Feb 24, 2012 at 13:15

3 Answers 3

1

I would use XSLT for this approach 9 times out of 10.

It depends on how much dynamic data you need to have in the HTML. If it's a good amount, or you need repeating rows of data, then XSLT is the way to go.

Here's a good start if you are unfamiliar with XSLT: XSLT Tutorial (W3Schools)

Sign up to request clarification or add additional context in comments.

Comments

1

check out this article http://cdmckay.org/blog/2009/02/01/creating-an-html-document-with-net/

The XML approach is a good start...

' Create the body element and append it to the root.
Dim xmlBody As XmlElement = xmlDoc.CreateElement("body")
xmlRoot.AppendChild(xmlBody)

Comments

0

Another option would be to use HtmlTextWriter.

1 Comment

So based on the quote below from MSDN I take it HtmlTextWriter only works for ASP.net applications. It isn't snowing up at all for my Windows forms app [HtmlTextWriter] - "Writes markup characters and text to an ASP.NET server control output stream. This class provides formatting capabilities that ASP.NET server controls use when rendering markup to clients."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.