I don't know if anyone can help with scripts buit I am trying to get this to work, it fails every time, not sure if it's a permissions thing. Password has been removed for obvious reasons, but correct one is in script on server.
Any ideas anyone ??
Any ideas anyone ??
Code:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using iTextSharp.text.pdf; using System.IO; using System.Net.Mail; namespace RetrieveForm { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string id = Session.SessionID; string fileName = id + ".pdf"; FileStream sw = new FileStream(Server.MapPath(fileName), FileMode.CreateNew); string file = Server.MapPath(fileName); PdfStamper ps = null; try { // read existing PDF document PdfReader r = new PdfReader( // optimize memory usage new RandomAccessFileOrArray(Server.MapPath("application.pdf")), null ); ps = new PdfStamper(r, sw); // retrieve properties of PDF form w/AcroFields object AcroFields af = ps.AcroFields; // fill in PDF fields by parameter: // 1. field name // 2. text to insert foreach (string key in Request.Form.Keys) { string v = Request.Form[key]; if (af.Fields.Contains(key)) { af.SetField(key, v); } } // make resultant PDF read-only for end-user ps.FormFlattening = true; // forget to close() PdfStamper, you end up with // a corrupted file! ps.Close(); sw.Close(); sendEmail(file); //File.Delete(file); Response.Write("<br/><h3>Your application was successfuly sent!<br/>Thanks.</h3>"); } catch (Exception err) { Response.Write(err.Message); } finally { if (ps != null) ps.Close(); } } private void sendEmail(string attachment) { SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.0-o-0.co.uk"; //Or Your SMTP Server Address smtp.Credentials = new System.Net.NetworkCredential ("[email protected]", "BLANKEDOUT"); smtp.EnableSsl = true; MailMessage mailMessage = new MailMessage(); mailMessage.From = new MailAddress("[email protected]", ""); mailMessage.To.Add(new MailAddress("[email protected]", "")); mailMessage.Subject = "Application submited"; mailMessage.Body = "Please find attached the PDF filled."; mailMessage.Attachments.Add(new Attachment(attachment)); smtp.Send(mailMessage); } } }
Comment