Render any object to HTML for Email with vb.net

Good morning. Well as you all know, Obama is now President Elect Obama. The amount of work ahead of him is staggering. Though i am not a Democrat, I want him to succeed. It is going to be an interesting next 4 years.

Today, we need to render any object (in this case a table) to HTML for the purpose of email. I needed to email a table. Not a lot of code or difficult but it worked for me. This was in an ASP.NET application. In my case I used

myMailMessage.Body = GetHTMLFromControl(myTable)

Make it a great day!

Public Function GetHTMLFromControl(ByRef TheControl As Object) As String
        Dim tw As IO.StringWriter = New IO.StringWriter
        Dim hw As Html32TextWriter = New Html32TextWriter(tw)
        TheControl.RenderControl(hw)
        Dim html As String = tw.ToString
        hw = Nothing
        tw = Nothing
        Return html
    End Function

 

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: