the code below creates a pdf file from an .aspx page. I want to be able send this pdf as an attachment.any ideas?
Imports NReco.PdfGenerator
Imports System.IO
Imports System.Net.Mail
Imports iTextSharp.text.pdf
Imports Microsoft.Office.Interop.Word
Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'creates pdf file from default.aspx
Dim customernumber As String = txtcustomer.Text
Dim accountnumber As String = txtaccountnumber.Text
Dim sr As StringWriter = New StringWriter()
HttpContext.Current.Server.Execute("Default.aspx", sr)
Dim htmlmessage As String = sr.ToString
Dim pdfBytes As Byte() = New HtmlToPdfConverter().GeneratePdf(htmlmessage)
'opens the pdf file
Dim response As HttpResponse = Me.Response
response.Clear()
response.BufferOutput = True
response.AppendCookie(New HttpCookie("fileDownloadToken", String.Format("{0}{1}", customernumber, accountnumber)))
response.AddHeader("Content-Type", "binary/octet-stream")
response.AddHeader("Content-Disposition", "inline; filename=" + String.Format("{0}{1}.pdf", customernumber, accountnumber))
response.ContentType = "application/pdf"
response.BinaryWrite(pdfBytes)
response.End()
'sends email
Dim strEmail As String = "someemail"
Dim mail As New System.Net.Mail.MailMessage()
Dim SmtpServer As New SmtpClient()
Try
SmtpServer.Port = 25
SmtpServer.Host = "mail.bel.com.bz"
mail = New System.Net.Mail.MailMessage()
mail.From = New MailAddress("someemail")
mail.To.Add(strEmail)
mail.Subject = "Service Application"
mail.Body = "Service Application Form"
SmtpServer.Send(mail)
Catch ex As Exception
End Try
'response.Redirect
End Sub
'Private Sub getpdf(ByVal data1() As Byte)
' Dim ms As MemoryStream = New MemoryStream(data1)
' Dim doc As Document = New Document()
' 'require custom parsers? add here.
' Dim writer As PdfWriter = PdfWriter.GetInstance(doc, ms)
' doc.Save()
' writer.CloseStream = False
' 'important
' doc.Close()
' 'build the doc.
' ms.Position = 0
' 'reset stream... important
'End Sub
End Class