这可能看起来像一个微不足道的问题,我想打开一个现有的pdf模板,编辑并压扁文件,然后作为电子邮件附件发送。但是,如何设置PdfReader来读取位于我的Content文件夹(Content/Documents/PDFFile.pdf)中的文件。这是我给出的错误“(无论我尝试的路径).pdf找不到作为文件或资源”。如何设置PdfReader文件路径?
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("[email protected]"));
msg.From = new MailAddress("[email protected]");
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;
}
任何建议/想法/建议?
,如果你使用绝对路径是否行得通?我还没有尝试,但我的第一个猜测是PDFReader没有正确解释'〜/'。 – Kendrick 2011-06-02 15:23:12
我使用了“../”,“../../”以及仍然没有运气 – MrM 2011-06-02 15:26:37
我正在考虑完整的本地路径,包括驱动器号等。 – Kendrick 2011-06-02 15:31:27