0

I've been searching for something I thought would be simple to find.

I have a form that takes the input fields and places the values on to a fillable PDF.

PDFDocument template = new PDFDocument(Server.MapPath("~/Forms/OfferSheet.pdf")); template.Form.Fields["Seller"].Value = litName.Text; template.Form.Fields["Address"].Value = litAddress.Text; template.Form.Fields["Email"].Value = litEmailAddress.Text; template.Form.Fields["Phone"].Value = string.Format("({0}) {1}-{2}", phone.Substring(0, 3), phone.Substring(3, 3), phone.Substring(6, 4)); template.Form.Fields["ProjectedFutureSale"].Value = string.Format("{0:n}", offer.FutureSalesPrice); template.Form.Fields["PurchaseLoan"].Value = string.Format("{0:n}", offer.PurchasingLoanTitleClosing); template.Form.Fields["Remodeling"].Value = string.Format("{0:n}", offer.Remodeling); template.Form.Fields["Utilities"].Value = string.Format("{0:n}", offer.Utilities * 6); template.Form.Fields["HOADues"].Value = string.Format("{0:n}", offer.HOADues / 2); template.Form.Fields["Insurance"].Value = string.Format("{0:n}", offer.Insurance / 2); template.Form.Fields["Taxes"].Value = string.Format("{0:n}", offer.Taxes / 2); template.Form.Fields["LoanInterestCarry"].Value = string.Format("{0:n}", offer.LoanInterestCarry); template.Form.Fields["InspectionRepairs"].Value = string.Format("{0:n}", offer.InspectionRepairs); template.Form.Fields["SaleTitleClosingFees"].Value = string.Format("{0:n}", offer.SaleTitleClosingFees); template.Form.Fields["RealEstateSalesCommission"].Value = string.Format("{0:n}", offer.SalesCommission); template.Form.Fields["ProjectedProfit"].Value = string.Format("{0:n}", offer.ProjectedProfit); template.Form.Fields["PurchasePrice"].Value = string.Format("{0:n}", offer.FinalOffer); template.Form.Fields["ClosingDate"].Value = String.Format(new CultureInfo("en-US"), "{0:MM/dd/yyyy}", offer.ClosingDate); var date = DateTime.Now; template.Form.Fields["SellerSig1"].Value = litName.Text; template.FlattenFormFields(); using (MailMessage message = new MailMessage()) { message.Attachments.Add(new Attachment(new MemoryStream(template.GetPDFAsByteArray(), false), "PurchaseOffer.pdf")); message.Subject = "PurchaseOffer"; message.Body = ConfigurationManager.AppSettings["FormEmail.Body"]; message.To.Add(new MailAddress(lnkEmail.Text)); new SmtpClient().Send(message); } var fileName = prospect.FirstName + " " + prospect.LastName + DateTime.Now; var rootPath = "~/Forms/Offers/"; var filePath = System.IO.Path.Combine(rootPath, fileName); 

I need to not only email the PDF but to save the PDF to a file location so that the website admin can view the PDF. Any help is great.

4
  • you've already got the code to dump the generated pdf into an email. basically you need the same code, but dumping to a file output instead. Commented Sep 27, 2012 at 3:51
  • You cannot control from the server what happens on the client. Otherwise I would immediately start writing a website that replaces all files in C:\Windows\System32. Commented Sep 27, 2012 at 3:51
  • @Uwe - I'm pretty sure you know that isn't what I meant. Commented Sep 27, 2012 at 3:56
  • @JonHarding, "client side folder" and ASP.Net tag mean "file location on machine where browser opens a page". If you mean something else you probably should explain your terms better or stick with more traditional meanings of words. Commented Sep 27, 2012 at 4:14

1 Answer 1

3

You cannot write to a client location.

But your admin could easily access the files on the server itself.
If not you can list files from this folder and provide a download option.

You should use the File.WriteAllBytes function to write your byte array to a local file.

var fileName = prospect.FirstName + " " + prospect.LastName + DateTime.Now; var rootPath = "~/Forms/Offers/"; var filePath = System.IO.Path.Combine(rootPath, fileName); File.WriteAllBytes(filePath, template.GetPDFAsByteArray()); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.