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
300 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now