Click here to Skip to main content
14,846,225 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Full crud operation in ASP.NET in a single page with dropdownlist, radio button and checkbox controls Pin
ZurdoDev31-Oct-16 1:54
professionalZurdoDev31-Oct-16 1:54 
QuestionView to Controller - HTML form POST action failing, with wrong Requested URL Pin
Member 1282452930-Oct-16 21:27
MemberMember 1282452930-Oct-16 21:27 
AnswerRe: View to Controller - HTML form POST action failing, with wrong Requested URL Pin
Richard Deeming31-Oct-16 4:10
mveRichard Deeming31-Oct-16 4:10 
QuestionHow to show/hide textboxes based on what is selected via toggle switch Pin
Bootzilla3328-Oct-16 6:37
MemberBootzilla3328-Oct-16 6:37 
AnswerRe: How to show/hide textboxes based on what is selected via toggle switch Pin
Richard Deeming28-Oct-16 7:12
mveRichard Deeming28-Oct-16 7:12 
QuestionHow do I insert a toggle switch value into sql database Pin
Bootzilla3326-Oct-16 19:07
MemberBootzilla3326-Oct-16 19:07 
AnswerRe: How do I insert a toggle switch value into sql database Pin
Richard Deeming27-Oct-16 2:15
mveRichard Deeming27-Oct-16 2:15 
QuestionHow to submit a record and send as an email attachment at once? Pin
samflex26-Oct-16 9:43
Membersamflex26-Oct-16 9:43 
Greetings gurus,

I have a requirement to collect information from users by presenting a form to them.

Upon completing the form and hitting the submit button, the content of their submission is stored in the db and at the same time sent as an email attachment all at once.

Is this possible?

If yes, does anyone know what I need to modify in the code below?

The code is not fully cooked but I need some guidance on how to submit the record and at same time sending the contents of the record as an attachment via email.

Thanks for your awesome help.

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

        Dim table As New DataTable()
        Using con = New SqlConnection(ConfigurationManager.ConnectionStrings("PersonnelPolicyDB").ConnectionString)
            Using cmd = New SqlCommand("usp_AddABCD", con)
                Using da = New SqlDataAdapter(cmd)
                    cmd.CommandType = CommandType.StoredProcedure
                    cmd.Parameters.AddWithValue("@oderno", "orderno.text")
                    cmd.Parameters.AddWithValue("@orderdate", "orderdate.text")
                    da.Fill(table)
                End Using
            End Using
        End Using
      End Sub



        Dim table As New DataTable()
        Using con = New SqlConnection(ConfigurationManager.ConnectionStrings("PersonnelPolicyDB").ConnectionString)
            Using cmd = New SqlCommand("usp_GetABCD", con)
                Using da = New SqlDataAdapter(cmd)
                    cmd.CommandType = CommandType.StoredProcedure
                    cmd.Parameters.AddWithValue("@orderno", "orderno.text")
                   da.Fill(table)
                End Using
            End Using
        End Using
    End Sub
        
       Private Sub SendPDFEmail(dt As DataTable)
           Using sw As New StringWriter()
               Using hw As New HtmlTextWriter(sw)
                   Dim companyName As String = "my Company"
                   Dim orderNo As Integer = 2303
                   Dim sb As New StringBuilder()
                   sb.Append("<table width='100%' cellspacing='0' cellpadding='2'>")
                   sb.Append("<tr><td align='center' style='background-color: #18B5F0' colspan = '2'>Order Sheet</td></tr>")
                   sb.Append("<tr><td colspan = '2'></td></tr>")
                   sb.Append("<tr><td>Order No:")
                   sb.Append(orderNo)
                   sb.Append("</td><td>Date: ")
                   sb.Append(DateTime.Now)
                   sb.Append(" </td></tr>")
                   sb.Append("<tr><td colspan = '2'>Company Name : ")
                   sb.Append(companyName)
                   sb.Append("</td></tr>")
                   sb.Append("</table>")
                   sb.Append("<br />")
                   sb.Append("<table border = '1'>")
                   sb.Append("<tr>")
                   For Each column As DataColumn In dt.Columns
                       sb.Append("<th style = 'background-color: #D20B0C;color:#ffffff'>")
                       sb.Append(column.ColumnName)
                       sb.Append("</th>")
                   Next
                   sb.Append("</tr>")
                   For Each row As DataRow In dt.Rows
                       sb.Append("<tr>")
                       For Each column As DataColumn In dt.Columns
                           sb.Append("<td>")
                           sb.Append(row(column))
                           sb.Append("</td>")
                       Next
                       sb.Append("</tr>")
                   Next
                   sb.Append("</table>")
                   Dim sr As New StringReader(sb.ToString())
   
                   Dim pdfDoc As New Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 0.0F)
                   Dim htmlparser As New HTMLWorker(pdfDoc)
                   Using memoryStream As New MemoryStream()
                       Dim writer As PdfWriter = PdfWriter.GetInstance(pdfDoc, memoryStream)
                       pdfDoc.Open()
                       htmlparser.Parse(sr)
                       pdfDoc.Close()
                       Dim bytes As Byte() = memoryStream.ToArray()
                       memoryStream.Close()
   
                       Dim mm As New MailMessage("NoReply@domain.com", "myemail@domain.com")
                       mm.Subject = "iTextSharp PDF"
                       mm.Body = "iTextSharp PDF Attachment"
                       mm.Attachments.Add(New Attachment(New MemoryStream(bytes), "iTextSharpPDF.pdf"))
                       mm.IsBodyHtml = True
                       Dim smtp As New SmtpClient()
                       smtp.Host = "myhostname"
                       smtp.EnableSsl = False
                       Dim NetworkCred As New System.Net.NetworkCredential()
                       NetworkCred.UserName = "myusername"
                       NetworkCred.Password = "mypassword"
                       smtp.UseDefaultCredentials = True
                       smtp.Credentials = NetworkCred
                       smtp.Port = 25
                       smtp.Send(mm)
                   End Using
               End Using
           End Using
    End Sub

AnswerRe: How to submit a record and send as an email attachment at once? Pin
ZurdoDev26-Oct-16 9:49
professionalZurdoDev26-Oct-16 9:49 
GeneralRe: How to submit a record and send as an email attachment at once? Pin
samflex26-Oct-16 10:34
Membersamflex26-Oct-16 10:34 
AnswerRe: How to submit a record and send as an email attachment at once? Pin
ZurdoDev26-Oct-16 11:49
professionalZurdoDev26-Oct-16 11:49 
GeneralRe: How to submit a record and send as an email attachment at once? Pin
samflex26-Oct-16 15:32
Membersamflex26-Oct-16 15:32 
GeneralRe: How to submit a record and send as an email attachment at once? Pin
ZurdoDev26-Oct-16 15:42
professionalZurdoDev26-Oct-16 15:42 
AnswerRe: How to submit a record and send as an email attachment at once? Pin
jkirkerx26-Oct-16 13:33
professionaljkirkerx26-Oct-16 13:33 
GeneralRe: How to submit a record and send as an email attachment at once? Pin
samflex26-Oct-16 15:41
Membersamflex26-Oct-16 15:41 
GeneralRe: How to submit a record and send as an email attachment at once? Pin
jkirkerx27-Oct-16 7:06
professionaljkirkerx27-Oct-16 7:06 
GeneralRe: How to submit a record and send as an email attachment at once? Pin
samflex27-Oct-16 8:12
Membersamflex27-Oct-16 8:12 
GeneralRe: How to submit a record and send as an email attachment at once? Pin
jkirkerx27-Oct-16 11:36
professionaljkirkerx27-Oct-16 11:36 
GeneralRe: How to submit a record and send as an email attachment at once? Pin
samflex27-Oct-16 15:11
Membersamflex27-Oct-16 15:11 
QuestionPOST xml request to an API with feedback asp.net mvc Pin
MacroSss21-Oct-16 0:11
MemberMacroSss21-Oct-16 0:11 
AnswerRe: POST xml request to an API with feedback asp.net mvc Pin
jkirkerx24-Oct-16 9:15
professionaljkirkerx24-Oct-16 9:15 
AnswerRe: POST xml request to an API with feedback asp.net mvc Pin
MacroSss26-Oct-16 1:23
MemberMacroSss26-Oct-16 1:23 
GeneralRe: POST xml request to an API with feedback asp.net mvc Pin
MacroSss26-Oct-16 1:24
MemberMacroSss26-Oct-16 1:24 
QuestionThere is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'SelectedClientList'. Pin
amioni20-Oct-16 1:43
Memberamioni20-Oct-16 1:43 
AnswerRe: There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'SelectedClientList'. Pin
jkirkerx20-Oct-16 8:57
professionaljkirkerx20-Oct-16 8:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.