这似乎是一个微不足道的问题,我想打开现有的pdf模板,编辑并展平文件,然后作为电子邮件附件发送。但是如何设置PdfReader来读取我的Content文件夹中的文件(Content / Documents / PDFFile.pdf)。这就是我所提供的错误“(无论我尝试什么路径).pdf都没有找到作为文件或资源”。
using (MemoryStream ms = new MemoryStream())
{
//Error is here...
PdfReader reader = new PdfReader("~/Content/Documents/PDFFile.pdf");
PdfStamper formFiller = new PdfStamper(reader, ms);
AcroFields formFields = formFiller.AcroFields;
formFields.SetField("Name", formData.Name);
formFields.SetField("Location", formData.Address);
formFields.SetField("Date", DateTime.Today.ToShortDateString());
formFields.SetField("Email", formData.Email);
formFiller.FormFlattening = true;
formFiller.Close();
MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress("to@email.com"));
msg.From = new MailAddress("from@email.com");
msg.Subject = "Application Form";
msg.Body = "TEST";
msg.IsBodyHtml = true;
msg.Attachments.Add(new Attachment(ms, "Application.pdf", "application/x-pdf"));
SmtpClient client = new SmtpClient("10.1.1.15");
client.UseDefaultCredentials = true;
}
有任何建议/想法/建议吗?
答案 0 :(得分:5)
尝试使用Server.MapPath("/Path/Here.pdf");
或Request.PhysicalApplicationPath("/Path/Here.pdf");