Example 09 - Advanced: Submit HTML, and e-mail the merged PDF, FDF data, xFDF data, or XML data

Imports FDFApp
Partial Public Class example_09
    Inherits System.Web.UI.Page
    Private Debug_Me As Boolean = False
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then
            Me.FULLNAME.Text = StripCodeFromString(Get_Cookie("Example_FULLNAME") & "")
            Me.EMAIL.Text = StripCodeFromString(Get_Cookie("Example_EMAIL") & "")
            'Me.COMBOBOX.SelectedValue = StripCodeFromString(Get_Cookie("Example_COMBOBOX") & "")
            'Me.CHECKBOX.Checked = StripCodeFromString(Get_Cookie("Example_CHECKBOX") & "")
            'Me.LISTBOX.SelectedValue = StripCodeFromString(Get_Cookie("Example_LISTBOX") & "")
            FULLNAME.Focus()
        End If
        Update_Message("Complete this form, verify captcha image, and then press send.")
    End Sub

    Private Sub Update_Message(ByVal strMsg As String)
        Me.lblMessage_Top.Text = "Status: " & strMsg
        Me.lblMessage_Bottom.Text = "Status: " & strMsg
    End Sub




    Public Sub Example()
        Me.form1.Target = "_self"
        ' DECLARE FDFApp & FDFDoc Classes
        Dim cFDFApp As New FDFApp.FDFApp_Class
        Dim cFDFDoc As New FDFApp.FDFDoc_Class
        ' INITIALIZE FDFDOC Class
        cFDFDoc = cFDFApp.FDFCreate
        ' SET FILE
        cFDFDoc.FDFSetFile(Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.LastIndexOf("/") + 1) & "example.pdf")
        ' SET FIELD VALUES
        cFDFDoc.FDFSetValue("FULLNAME", StripCodeFromString(Me.FULLNAME.Text & ""))
        cFDFDoc.FDFSetValue("EMAIL", StripCodeFromString(Me.EMAIL.Text & ""))
        cFDFDoc.FDFSetValue("COMBOBOX", StripCodeFromString(Me.COMBOBOX.SelectedValue.ToString() & ""))
        cFDFDoc.FDFSetValue("CHECKBOX", Me.CHECKBOX.Checked.ToString())
        cFDFDoc.FDFSetValue("LISTBOX", StripCodeFromString(Me.LISTBOX.SelectedValue.ToString() & ""))
        cFDFDoc.FDFSetValue("RADIOBUTTON", Me.frmRadiobutton0.Checked.ToString())

        Store_Cookie("Example_FULLNAME", StripCodeFromString(Me.FULLNAME.Text))
        Store_Cookie("Example_EMAIL", StripCodeFromString(Me.EMAIL.Text))
        'Store_Cookie("Example_COMBOBOX", StripCodeFromString(Me.COMBOBOX.SelectedValue))
        'Store_Cookie("Example_CHECKBOX", StripCodeFromString(Me.CHECKBOX.Checked.ToString()))
        'Store_Cookie("Example_LISTBOX", StripCodeFromString(Me.LISTBOX.SelectedValue))
        'Store_Cookie("Example_RADIOBUTTON", StripCodeFromString(Me.frmRadiobutton0.Checked.ToString()))

        ' SET FRAME
        cFDFDoc.FDFSetTargetFrame = "frame_examples"
        ' SET DOC JAVASCRIPT
        cFDFDoc.FDFSetOnImportJavaScript("var x = app.alert('Thank you for trying FDFToolkit.net!',3);", False)
        ' CREATE MESSAGE 
        Dim cMsg As New FDFApp.Mail.MailMessage
        cMsg.msgSubject = "FDFToolkit.net - Examples"
        Dim msgBody As String = "Thank you for trying FDFToolkit.net"
        msgBody &= Environment.NewLine & ""
        msgBody &= Environment.NewLine & "URL:" & Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.LastIndexOf("/") + 1)
        msgBody &= Environment.NewLine & "Example 09"
        msgBody &= Environment.NewLine & ""
        msgBody &= Environment.NewLine & "See attached file"
        cMsg.msgBodyFormatIsHTML = False
        cMsg.msgFromAddress = New System.Net.Mail.MailAddress("no-reply@nk-inc.com", "FDFToolkit.net")
        cMsg.msgTo.Add(New System.Net.Mail.MailAddress(StripCodeFromString(Me.EMAIL.Text & ""), StripCodeFromString(Me.FULLNAME.Text & "")))
        Dim cSMTP As New FDFApp.Mail.SMTPServer

        cSMTP.SMTPUserName = ""
        cSMTP.SMTPPassword = ""
        cSMTP.SMTPServerName = ""

        cSMTP.SMTPServerPort = 25
        cSMTP.SMTPConnectionTimeOut = 10000
        Dim msgSent As Boolean = False
        Try
            ' CREATE MERGED PDF FILE MESSAGE ATTACHMENT AND SEND
            If frmPDF_Format1.Checked Then
                msgBody &= Environment.NewLine & "Attachment format: " & "PDF"
                msgBody &= Environment.NewLine & "Attachment file name: " & Me.frmPDF_FileName.Text.Substring(0, Me.frmPDF_FileName.Text.LastIndexOf(".") + 1) & "PDF"
                cMsg.msgBody = msgBody
                msgSent = cSMTP.PDFSendEmail(cMsg.msgMailMessage, cFDFDoc.PDFMergeFDF2Buf(Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.LastIndexOf("/") + 1) & "example.pdf", Me.frmPDF_Flatten.Checked, ""), Me.frmPDF_FileName.Text, FDFDoc_Class.FDFType.PDF, Me.frmPDF_Flatten.Checked)
            ElseIf frmPDF_Format2.Checked Then
                msgBody &= Environment.NewLine & "Attachment file name: " & Me.frmPDF_FileName.Text.Substring(0, Me.frmPDF_FileName.Text.LastIndexOf(".") + 1) & "FDF"
                cMsg.msgBody = msgBody
                msgSent = cSMTP.FDFSendEmail(cMsg.msgMailMessage, cFDFDoc, Me.frmPDF_FileName.Text, FDFDoc_Class.FDFType.FDF)
            ElseIf frmPDF_Format3.Checked Then
                msgBody &= Environment.NewLine & "Attachment file name: " & Me.frmPDF_FileName.Text.Substring(0, Me.frmPDF_FileName.Text.LastIndexOf(".") + 1) & "xFDF"
                cMsg.msgBody = msgBody
                msgSent = cSMTP.FDFSendEmail(cMsg.msgMailMessage, cFDFDoc, Me.frmPDF_FileName.Text, FDFDoc_Class.FDFType.xFDF)
            ElseIf frmPDF_Format4.Checked Then
                msgBody &= Environment.NewLine & "Attachment file name: " & Me.frmPDF_FileName.Text.Substring(0, Me.frmPDF_FileName.Text.LastIndexOf(".") + 1) & "XML"
                cMsg.msgBody = msgBody
                msgSent = cSMTP.FDFSendEmail(cMsg.msgMailMessage, cFDFDoc, Me.frmPDF_FileName.Text, FDFDoc_Class.FDFType.XML)
            ElseIf frmPDF_Format5.Checked Then
                msgBody &= Environment.NewLine & "Attachment file name: " & Me.frmPDF_FileName.Text.Substring(0, Me.frmPDF_FileName.Text.LastIndexOf(".") + 1) & "XDP"
                cMsg.msgBody = msgBody
                msgSent = cSMTP.FDFSendEmail(cMsg.msgMailMessage, cFDFDoc, Me.frmPDF_FileName.Text, FDFDoc_Class.FDFType.XDP)
            End If
        Catch ex As Exception
            msgSent = False
        End Try
        If msgSent Then
            Update_Message("Your message was sent successfully!")
        Else
            Update_Message("Sorry, your message was not sent successfully!")
        End If
        Exit Sub
    End Sub

    Private Sub btnRunExample_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRunExample.Click
        Example()
    End Sub
End Class