PC Review


Reply
Thread Tools Rate Thread

Emailing rows of text into an E-mail body.

 
 
=?Utf-8?B?TWljaGFlbCBkZSBWZXJh?=
Guest
Posts: n/a
 
      1st Feb 2007
To all,

I was wondering if someone has sample VB.NET code that will help me send
rows of a gridview into a body section of an e-mail. My goal is to present
multiple rows within a gridview to a table like format within an e-mail
message.

Thanks for any help,
Michael
 
Reply With Quote
 
 
 
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      2nd Feb 2007
Hi Michael,

Short answer:

1) Create following class:

Public Class EmailReadyPage
Inherits System.Web.UI.Page

Public Overrides Sub VerifyRenderingInServerForm(ByVal control As
System.Web.UI.Control)
'DO NOTHING
End Sub
End Class

2) Inherit your WebForm from above class.

3) In server-side code:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim sb As New StringBuilder
Dim sw As New IO.StringWriter(sb)
Dim writer As New HtmlTextWriter(sw)
GridView1.RenderControl(writer)

Dim mail As New Net.Mail.MailMessage

mail.From = New Net.Mail.MailAddress(...)
mail.To.Add(...)
mail.Subject = "This is the GridView's output"

mail.IsBodyHtml = True
mail.Body = sb.ToString()

Dim smtp As New Net.Mail.SmtpClient(...)
' set smtp.Credentials if necessary
smtp.Send(mail)
End Sub


Long answer:

#ASP.NET.4GuysFromRolla.com: Enhancing the 'Email the Rendered Output of an
ASP.NET Web Control' Code
http://aspnet.4guysfromrolla.com/articles/102203-1.aspx

#ASP.NET.4GuysFromRolla.com: Enhancing the 'Email the Rendered Output of an
ASP.NET Web Control' Code, Part 2
http://aspnet.4guysfromrolla.com/art...02203-1.2.aspx


Hope this helps.

Sincerely,
Walter Wang ((E-Mail Removed), remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWljaGFlbCBkZSBWZXJh?=
Guest
Posts: n/a
 
      2nd Feb 2007
Walter,

This looks like it will definitely work! Thank you so much!

Michael

"Walter Wang [MSFT]" wrote:

> Hi Michael,
>
> Short answer:
>
> 1) Create following class:
>
> Public Class EmailReadyPage
> Inherits System.Web.UI.Page
>
> Public Overrides Sub VerifyRenderingInServerForm(ByVal control As
> System.Web.UI.Control)
> 'DO NOTHING
> End Sub
> End Class
>
> 2) Inherit your WebForm from above class.
>
> 3) In server-side code:
>
> Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
> System.EventArgs)
> Dim sb As New StringBuilder
> Dim sw As New IO.StringWriter(sb)
> Dim writer As New HtmlTextWriter(sw)
> GridView1.RenderControl(writer)
>
> Dim mail As New Net.Mail.MailMessage
>
> mail.From = New Net.Mail.MailAddress(...)
> mail.To.Add(...)
> mail.Subject = "This is the GridView's output"
>
> mail.IsBodyHtml = True
> mail.Body = sb.ToString()
>
> Dim smtp As New Net.Mail.SmtpClient(...)
> ' set smtp.Credentials if necessary
> smtp.Send(mail)
> End Sub
>
>
> Long answer:
>
> #ASP.NET.4GuysFromRolla.com: Enhancing the 'Email the Rendered Output of an
> ASP.NET Web Control' Code
> http://aspnet.4guysfromrolla.com/articles/102203-1.aspx
>
> #ASP.NET.4GuysFromRolla.com: Enhancing the 'Email the Rendered Output of an
> ASP.NET Web Control' Code, Part 2
> http://aspnet.4guysfromrolla.com/art...02203-1.2.aspx
>
>
> Hope this helps.
>
> Sincerely,
> Walter Wang ((E-Mail Removed), remove 'online.')
> Microsoft Online Community Support
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscripti...ult.aspx#notif
> ications. If you are using Outlook Express, please make sure you clear the
> check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
> promptly.
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscripti...t/default.aspx.
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Emailing using message text. How to increase the text limit SGangs Microsoft Access Macros 0 23rd Jun 2009 12:11 PM
FONT / ROW ACCESS 2007 Unable to change font size or colour of individual text or heigth of individual rows without all text & rows changing moto Microsoft Access 1 12th Nov 2008 08:23 PM
"Add/Remove Rows Code" adds rows on grouped sheets, but won't remove rows. Conan Kelly Microsoft Excel Programming 1 16th Nov 2007 11:41 PM
Changing columns into rows and rows into columns =?Utf-8?B?Ymhvd2s=?= Microsoft Access Getting Started 1 6th Jun 2007 12:41 AM
How can i convert the rows into columns and columns into rows? =?Utf-8?B?WWFzc2Vy?= Microsoft Excel Worksheet Functions 1 7th Aug 2005 07:38 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:11 PM.