Solved

How do I convert a table object to a string for an HTML email or insert table object into body of HTML email?

Posted on 2008-10-07
2
303 Views
Last Modified: 2013-11-19
I have a function that returns a table to display what a user has purchased for their receipt.
I am displaying the page when the user completes their order, but I'd also like to email the user a copy of the receipt.
The problem I am facing is the email class I'm using (MailMessage) only accepts a String for the body.
Thus, my originally intended code (myMailMessage.Body = myTable) is unacceptable.

I need to either convert the myTable object into a string or find a way to implement my table into the body of this html email message.
(I'm using VB .NET)
0
Comment
Question by:ManageMobility
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 500 total points
ID: 22659026
Hello ManageMobility,

This function will render any control to html. In your case you could use: myMailMessage.Body = GetHTMLFromControl(myTable)

Regards,

TimCottee
    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

Open in new window

0
 
LVL 2

Author Closing Comment

by:ManageMobility
ID: 31503822
That was the fastest and probably best response I've ever gotten from any IT assistance site. Thank you very much!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

856 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