Click here to Skip to main content
15,887,683 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: Two way binding in AngularJS Pin
Nathan Minier21-Dec-16 4:44
professionalNathan Minier21-Dec-16 4:44 
GeneralRe: Two way binding in AngularJS Pin
Member 1110597421-Dec-16 4:57
Member 1110597421-Dec-16 4:57 
GeneralRe: Two way binding in AngularJS Pin
Nathan Minier21-Dec-16 5:12
professionalNathan Minier21-Dec-16 5:12 
GeneralRe: Two way binding in AngularJS Pin
Member 1110597422-Dec-16 4:40
Member 1110597422-Dec-16 4:40 
GeneralRe: Two way binding in AngularJS Pin
Nathan Minier23-Dec-16 1:01
professionalNathan Minier23-Dec-16 1:01 
Questionnpm install is giving error that project.json file doesn't exist even it exists Pin
indian1435-Dec-16 7:35
indian1435-Dec-16 7:35 
AnswerRe: npm install is giving error that project.json file doesn't exist even it exists Pin
John C Rayan30-Dec-16 4:38
professionalJohn C Rayan30-Dec-16 4:38 
QuestionSend as .pdf email attachment, job application form with asp.net Pin
TaRoshka3-Dec-16 0:43
TaRoshka3-Dec-16 0:43 
Hello,

I have created a job application form.
I need to send this form converted as .pdf file via mail.
Code behind
C#
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.html;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Text;
using System.Net.Mime;
using System.IO;

namespace myproject
{
    public partial class ApplicationForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //Remove the session when first time page loads.
                Session.Remove("clicks");
            }
        }
        protected MemoryStream getMemoryStream()
        {
            StringWriter sw = new StringWriter();
            HtmlTextWriter w = new HtmlTextWriter(sw);
            this.Page.RenderControl(w);
            string s = sw.GetStringBuilder().ToString();
            SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();
            SelectPdf.PdfDocument doc = converter.ConvertHtmlString(s); 
            MemoryStream Stream = new MemoryStream();
            doc.Save(Stream);
            doc.Close();
            return Stream;
           // Stream.WriteTo(Response.OutputStream);
          //  Stream.Close();
            
        }

        protected String getHtml()
        {
            StringWriter sw = new StringWriter();
            HtmlTextWriter w = new HtmlTextWriter(sw);
            this.Page.RenderControl(w);
            string s = sw.GetStringBuilder().ToString();
            return s;

        }

        protected void add_Click(object sender, EventArgs e)
        {
            int rowCount = 7;

            //initialize a session.
            rowCount = Convert.ToInt32(Session["clicks"]);

            rowCount++;

            //In each button clic save the numbers into the session.
            Session["clicks"] = rowCount;


            //Create the textboxes and labels each time the button is clicked.
            for (int i = 0; i < rowCount; i++)
            {

                TextBox TxtBoxE = new TextBox();
                TextBox TxtBoxP = new TextBox();
                TextBox TxtBoxD = new TextBox();
                TextBox TxtBoxS = new TextBox();
                TextBox TxtBoxR = new TextBox();

                Label lblE = new Label();
                Label lblP = new Label();
                Label lblD = new Label();
                Label lblS = new Label();
                Label lblR = new Label();

                TxtBoxE.ID = "TextBoxE" + i.ToString();
                TxtBoxP.ID = "TextBoxP" + i.ToString();
                TxtBoxD.ID = "TextBoxD" + i.ToString();
                TxtBoxS.ID = "TextBoxS" + i.ToString();
                TxtBoxR.ID = "TextBoxR" + i.ToString();

                lblE.ID = "LabelE" + i.ToString();
                lblP.ID = "LabelP" + i.ToString();
                lblD.ID = "LabelD" + i.ToString();
                lblS.ID = "LabelS" + i.ToString();
                lblR.ID = "LabelR" + i.ToString();

                lblE.ID = "LabelE" + i.ToString();
                lblP.ID = "LabelP" + i.ToString();
                lblD.ID = "LabelD" + i.ToString();
                lblS.ID = "LabelS" + i.ToString();
                lblR.ID = "LabelR" + i.ToString();

                lblE.ID = "LabelE" + i.ToString();
                lblP.ID = "LabelP" + i.ToString();
                lblD.ID = "LabelD" + i.ToString();
                lblS.ID = "LabelS" + i.ToString();
                lblR.ID = "LabelR" + i.ToString();

                lblE.ID = "LabelE" + i.ToString();
                lblP.ID = "LabelP" + i.ToString();
                lblD.ID = "LabelD" + i.ToString();
                lblS.ID = "LabelS" + i.ToString();
                lblR.ID = "LabelR" + i.ToString();


                lblE.Text = "Employer " + (i + 1).ToString() + " : ";
                lblP.Text = "Position " + (i + 1).ToString() + " : ";
                lblD.Text = "From-Until : ";
                lblS.Text = "Salary " + (i + 1).ToString() + " : ";
                lblR.Text = "Reason for Leaving " + (i + 1).ToString() + " : ";


                //Add the labels and textboxes to the Panel.
                Panel1.Controls.Add(lblE);
                Panel1.Controls.Add(TxtBoxE);

                Panel1.Controls.Add(lblP);
                Panel1.Controls.Add(TxtBoxP);

                Panel1.Controls.Add(lblD);
                Panel1.Controls.Add(TxtBoxD);

                Panel1.Controls.Add(lblS);
                Panel1.Controls.Add(TxtBoxS);

                Panel1.Controls.Add(lblR);
                Panel1.Controls.Add(TxtBoxR);

            }
        }
        protected void btnsubmit_Click(object sender, EventArgs e)
    {
            string fname = "applicationForm" + DateTime.Now.ToString("yyMMddHHmmss") + ".pdf";


          //  try
          //  {
                MailMessage mailMsg = new MailMessage();

                mailMsg.From = new MailAddress(txtmymail.Text);

                mailMsg.To.Add("my-email@gmail.com");

                mailMsg.IsBodyHtml = true;

                mailMsg.Subject = "Contact Details";
             //   try
             //   {
                    MemoryStream file = getMemoryStream();
                    FileStream filePDF = new FileStream(fname, FileMode.Create, FileAccess.Write);
                    file.WriteTo(filePDF);

                    file.Close();
                    filePDF.Close();
              ///  }
             //   catch (Exception excvb) {

             //   }

                System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType(System.Net.Mime.MediaTypeNames.Application.Pdf);
                System.Net.Mail.Attachment attach = new System.Net.Mail.Attachment(fname, ct);
                attach.ContentDisposition.FileName = fname;

                // I guess you know how to send email with an attachment
                // after sending email
                //

                
                 
                // Add time stamp information for the file.
                ContentDisposition disposition = attach.ContentDisposition;
               disposition.CreationDate = DateTime.Now; 
              //   Add the file attachment to this e-mail message.
               mailMsg.Attachments.Add(attach);
                // StringBuilder sb = new StringBuilder();
                //  sb.Append(getHtml()); 
                // mailMsg.Body = sb.ToString(); 
                SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);

                mailMsg.Priority = MailPriority.Normal;

                smtp.Credentials = new System.Net.NetworkCredential("my-email@gmail.com", "my-email-password");

                smtp.Timeout = 250000;

                smtp.EnableSsl = true;
                System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate(object s,
                        System.Security.Cryptography.X509Certificates.X509Certificate certificate,
                        System.Security.Cryptography.X509Certificates.X509Chain chain,
                        System.Net.Security.SslPolicyErrors sslPolicyErrors)
                {
                    return true;
                };
                smtp.Send(mailMsg);
                Response.Write("<Script>alert('Thanks for contact us,our team will be contact you as soon as possible')</Script>");
                // Clear the textbox values
                txtfname.Text = "";
                txtlname.Text = "";
                txtfaname.Text = "";
                txtmoname.Text = "";
                txtmymail.Text = "";
                

          //  }
           // catch (Exception ex)
         //   {
             //   Response.Write(ex.Message);

          //  }
        }

    }
}

ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ApplicationForm.aspx.cs" EnableEventValidation="false" Inherits="icts.ApplicationForm" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server" >
    <meta charset="UTF-8"/>
    <title>Job Application</title>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"/>
    <link href="css/bootstrap.min.css" rel="stylesheet"/>
    <link href="css/style.css" rel="stylesheet"/>
</head>
<body>
    <form method="get" runat="server" id="form1">
<div class="container">
<h5>GENERAL INFORMATION</h5>
     <div class="row">
	        <div class="col-md-6" id="col-md-6">
               <div class="col-sm-9">
                    <div class="col-xs-8 col-sm-6">
					    <span>Surname</span>
					</div>
				    <div class="col-xs-8 col-sm-6">
                         <asp:TextBox ID="txtlname" runat="server"></asp:TextBox>
		            </div>
				</div>
			</div>
			<div class="col-md-6">
				<div class="col-sm-9">
                        <div class="col-xs-8 col-sm-6">
					      <span>Name</span>
					    </div>
					    <div class="col-xs-8 col-sm-6">
                            <asp:TextBox ID="txtfname" runat="server"></asp:TextBox>
					    </div>
		        </div>
		    </div>
       </div>
<div class="row">
 	        <div class="col-md-6" id="col-md-6">
               <div class="col-sm-9">
                    <div class="col-xs-8 col-sm-6">
					     <span>Date of Birth</span>
                    </div>
				    <div class="col-xs-8 col-sm-6">						
                        <asp:Textbox  type="date" runat="server" ID="bday"></asp:Textbox>
				    </div>
				</div>
			</div>
    <!--dynamic row-->
      <div class="row">
          <div class="col-md-12">
                
               <asp:Panel ID= "Panel1"  runat = "server"></asp:Panel>
              <asp:Button ID="Button2" runat="server" Text="Add field" OnClick="add_Click" />
          </div>
       </div>
		<div class="row">
                <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="btnsubmit_Click" />
		</div>

With this code i am able to send a .pdf attachment via mail, but some of the fields are empty.
My form has text boxes, date input and radio buttons.

What would you suggest?

Thank you,
AnswerRe: Send as .pdf email attachment, job application form with asp.net Pin
Nathan Minier3-Dec-16 3:49
professionalNathan Minier3-Dec-16 3:49 
Questionweb developer Pin
Member 1284786913-Nov-16 6:37
Member 1284786913-Nov-16 6:37 
AnswerRe: web developer Pin
Richard MacCutchan13-Nov-16 21:43
mveRichard MacCutchan13-Nov-16 21:43 
AnswerRe: web developer Pin
ZurdoDev16-Nov-16 1:15
professionalZurdoDev16-Nov-16 1:15 
QuestionVimeo Sample code to fetch private videos using REST/ JSON/ JQuery Pin
Elena200612-Nov-16 0:03
Elena200612-Nov-16 0:03 
AnswerRe: Vimeo Sample code to fetch private videos using REST/ JSON/ JQuery Pin
ZurdoDev15-Nov-16 2:00
professionalZurdoDev15-Nov-16 2:00 
QuestionHow do I get apis for Facebook, Google talk, skype, whatsapp for my project using javascript and html Pin
Member 1233604411-Nov-16 17:36
Member 1233604411-Nov-16 17:36 
AnswerRe: How do I get apis for Facebook, Google talk, skype, whatsapp for my project using javascript and html Pin
Richard MacCutchan11-Nov-16 21:55
mveRichard MacCutchan11-Nov-16 21:55 
GeneralRe: How do I get apis for Facebook, Google talk, skype, whatsapp for my project using javascript and html Pin
Member 1233604412-Nov-16 0:13
Member 1233604412-Nov-16 0:13 
QuestionRe: How do I get apis for Facebook, Google talk, skype, whatsapp for my project using javascript and html Pin
Richard MacCutchan12-Nov-16 0:22
mveRichard MacCutchan12-Nov-16 0:22 
AnswerRe: How do I get apis for Facebook, Google talk, skype, whatsapp for my project using javascript and html Pin
Member 1233604412-Nov-16 1:53
Member 1233604412-Nov-16 1:53 
GeneralRe: How do I get apis for Facebook, Google talk, skype, whatsapp for my project using javascript and html Pin
Richard MacCutchan12-Nov-16 2:05
mveRichard MacCutchan12-Nov-16 2:05 
AnswerRe: How do I get apis for Facebook, Google talk, skype, whatsapp for my project using javascript and html Pin
biji cabe16-Dec-16 18:23
biji cabe16-Dec-16 18:23 
GeneralRe: How do I get apis for Facebook, Google talk, skype, whatsapp for my project using javascript and html Pin
nanik8817-Dec-16 21:30
nanik8817-Dec-16 21:30 
QuestionHow to trigger on change on a HTML5 var tag? Pin
Nicky Tse11-Nov-16 2:29
Nicky Tse11-Nov-16 2:29 
Rant[REPOST] How to trigger on change on a HTML5 var tag? Pin
Richard Deeming11-Nov-16 3:21
mveRichard Deeming11-Nov-16 3:21 
AnswerRe: How to trigger on change on a HTML5 var tag? Pin
Peter Leow11-Nov-16 3:41
professionalPeter Leow11-Nov-16 3:41 

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.