protected void btnDownload_Click(object sender, EventArgs e) { Common _objCommon = new Common(); string Msg = ""; var userid = 0; if (Utils.IsEmailValid(txtEmailId.Text)) { MailTemplates _objMailTemplete = new MailTemplates(); if (Utils.IsMobileValid(txtMobile.Text)) { QueryProperty objQueryProperty = new QueryProperty { StudentName = txtName.Text, UserEmailId = txtEmailId.Text, UserMobileNo = txtMobile.Text, StudentCityName = "", StudentCourseId = Convert.ToInt16(ddlCourse.SelectedValue), StudentQuery = "User Download the Application from", StudentCourseName = ddlCourse.SelectedItem.ToString(), }; int i = QueryProvider.Instance.InsertCommonQuickQuery(objQueryProperty, out Msg, out userid); if (i == 2) { var ObjMail = new MailMessage { From = new MailAddress(ApplicationSettings.Instance.Email), Subject = "AdmissionJankari:Registration" }; var mailbody = _objMailTemplete.MailBodyForRegistation(txtName.Text, txtEmailId.Text, txtMobile.Text); ObjMail.Body = mailbody; ObjMail.To.Add(objQueryProperty.UserEmailId); ObjMail.IsBodyHtml = true; Utils.SendMailMessageAsync(ObjMail); } var mail = new MailMessage { From = new MailAddress(ApplicationSettings.Instance.Email), Subject = "AdmissionJankari:Download the application form" }; var body = _objMailTemplete.MailBodyForDownloadApplicationfrom(txtName.Text, ddlCourse.SelectedItem.ToString()); mail.Body = body; mail.To.Add(objQueryProperty.UserEmailId); mail.IsBodyHtml = true; Utils.SendMailMessageAsync(mail); mail = new MailMessage { From = new MailAddress(ApplicationSettings.Instance.Email), Subject = "AdmissionJankari:Download the application form" }; body = _objMailTemplete.MailBodyForAdminToDownloadApplicationfrom(txtName.Text, ddlCourse.SelectedItem.ToString(), txtMobile.Text); mail.Body = body; mail.To.Add(ClsSingelton.bccDirectAdmission); mail.IsBodyHtml = true; Utils.SendMailMessageAsync(mail); ClearControl(); try { ClearControl(); lblMsg.Visible = true; lblMsg.Text = "Thank you for downloading the application form"; string fName = HttpContext.Current.Server.MapPath("\\Resource\\Download") + @"\" + "ApplicationForm_FinalDec12_2012.pdf"; FileInfo fi = new FileInfo(fName); long sz = fi.Length; Response.ClearContent(); Response.ContentType = MimeType(Path.GetExtension(fName)); Response.AddHeader("Content-Disposition", string.Format("attachment; filename = {0}", System.IO.Path.GetFileName(fName))); Response.AddHeader("Content-Length", sz.ToString("F0")); Response.TransmitFile(fName); Response.End(); } catch (Exception ex) { ClearControl(); lblMsg.Visible = true; lblMsg.Text = "Thank you for downloading the application form"; } } else { lblMsg.Visible = true; lblMsg.Text = _objCommon.GetValidationMessage("revContactNo"); } } else { lblMsg.Visible = true; lblMsg.Text = _objCommon.GetValidationMessage("revEmail"); } }